NestJS API应用程序使用HttpService调用另一个API,并且在不使用自定义拦截器的情况下可以正常工作。 HttpService API调用已执行,但未到达另一个API并且看不到响应。
这是获取呼叫代码
"start rating html"
如果使用任何自定义拦截器,则在调试时会发现以下内容。
get(path: string, body: any = {}): Observable<AxiosResponse<any>> {
console.log('DomainAPI Response Begining');
const url = this.baseURL + path;
this.updateLastUtilizedTimestamp();
return this.httpService.get(url, { validateStatus: null }).pipe(
tap(data => {
console.log('DomainAPI Response Tap', data);
}),
retryWhen(
this.rxJSUtilsService.genericRetryStrategy({
numberOfAttempts: 3,
delayTime: 200,
ignoredErrorCodes: [500],
}),
),
catchError(this.formatErrors),
);
}
邮递员显示以下答复。
arguments:TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
我如下更改了上述内容,但仍然无法正常工作
{
"statusCode": 500,
"message": {
"Title": "TypeError",
"Type": "Error",
"Detail": "Converting circular structure to JSON\n --> starting at object with constructor 'Observable'\n | property 'operator' -> object with constructor 'CatchOperator'\n --- property 'caught' closes the circle",
"Status": "Status",
"Extension": ""
},
"timestamp": "Exception - AllExceptionsFilter 2019-12-26T17:29:42.447Z"
}
在邮递员中给出以下答复
get(path: string, body: any = {}) {
console.log('DomainAPI Response Begining');
const url = this.baseURL + path;
this.updateLastUtilizedTimestamp();
return this.httpService.get(url, { validateStatus: null }).pipe(
map(response => {
console.log('DomainAPI Response Tap', response.data);
return response.data;
}),
);
}
请告知
答案 0 :(得分:0)
async get(path: string, body: any = {}): Promise<any> {
...
const res = await this.httpService.get(url, { validateStatus: null }).toPromise();
return res.data;
}
答案 1 :(得分:0)
get(path: string, body: any = {}) {
...
return this.httpService.get(url, { validateStatus: null })
.toPromise()
.then(res => res.data)
.catch(err => this.logger.error(err));
}