javascript - ERROR 错误:未捕获(在承诺中):错误:调用 getActive 时必需的参数参与者 ID 为空或未定义
问题描述
我正在使用 Angular 8 应用程序和 api 调用的招摇。我有这项服务:
@Injectable({
providedIn: 'root'
})
export class ObjectiveService {
constructor(private http: HttpClient, private challengeService: ChallengeService) {}
getChallenges(patientUUID: string): Observable<ChallengeDTO[]> {
return this.challengeService.getActive(patientUUID);
}
}
swagger api 调用如下所示:
public getActive(participantId: string, observe?: 'body', reportProgress?: boolean): Observable<Array<ChallengeDTO>>;
public getActive(participantId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<Array<ChallengeDTO>>>;
public getActive(participantId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<Array<ChallengeDTO>>>;
public getActive(participantId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
if (participantId === null || participantId === undefined) {
throw new Error('Required parameter participantId was null or undefined when calling getActive.');
}
let headers = this.defaultHeaders;
// authentication (Bearer) required
if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken()
: this.configuration.accessToken;
headers = headers.set('Authorization', 'Bearer ' + accessToken);
}
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'text/plain',
'application/json',
'text/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected !== undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected);
}
// to determine the Content-Type header
const consumes: string[] = [
];
return this.httpClient.get<Array<ChallengeDTO>>(`${this.configuration.basePath}/api/patient/${encodeURIComponent(String(participantId))}/Challenge`,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}
所以我用方法传递了一个id。但我仍然收到此错误:
core.js:7376 ERROR Error: Uncaught (in promise): Error: Required parameter participantId was null or undefined when calling getActive.
Error: Required parameter participantId was null or undefined when calling getActive.
at ChallengeService.push../src/app/generated/api/challenge.service.ts.ChallengeService.getActive (challenge.service.ts:76)
但如果我硬编码参与者 ID,例如这样:
getChallenges(patientUUID: string): Observable<ChallengeDTO[]> {
return this.challengeService.getActive('0d584905-fc20-4723-870a-0f0214419507');
}
然后它工作。
那么我必须改变什么?
谢谢
解决方案
推荐阅读
- perl - 如何获取 DateTime::Format::Strptime 来解析闰秒的日期/时间?
- javascript - 如何使 AppBar 背景颜色与导航栏颜色一致
- machine-learning - 如何在前馈神经网络中使用三通道图像?
- javascript - 如何禁用 Bootstraps 按钮复选框悬停和焦点效果?
- javascript - 如何在客户端渲染之前清理 HTML 输入值,我们可以过滤允许的标签
- python - 用pickle加载一个类的实例?
- python - 如何使用队列实现堆栈接口?
- docker - 如何调试 TLS/SSL 连接
- python - `SyntaxError.print_file_and_line` 有什么用?
- python - 如何将所有类变量从父 *instance* 传递给子类?