首页 > 解决方案 > 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');
  }

然后它工作。

那么我必须改变什么?

谢谢

标签: javascriptangularswagger

解决方案


推荐阅读