错误错误:未捕获(承诺):错误:调用getActive时必需的参数particatorId为空或未定义

时间:2020-03-02 14:43:13

标签: javascript angular swagger

我正在使用带有8位角的api应用程序进行api调用。我有这项服务:

if (!message.guild.me.hasPermission("ADMINISTRATOR")) return;

和招摇的api调用看起来像这样:

@Injectable({
  providedIn: 'root'
})
export class ObjectiveService {



  constructor(private http: HttpClient, private challengeService: ChallengeService) {}

  getChallenges(patientUUID: string): Observable<ChallengeDTO[]> {
    return   this.challengeService.getActive(patientUUID);
  }
}

所以我通过方法传递了一个id。但我仍然收到此错误:


 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)

然后它起作用。

那我要改变什么?

谢谢

0 个答案:

没有答案