【发布时间】:2021-08-14 08:47:03
【问题描述】:
我正在尝试创建一个与我的angular 应用程序通信的Slack 应用程序,我感觉好像我非常接近让它工作但是我得到了以下错误:
这是我在 angular 应用程序中调用 webhook 的方式:
this.http.post<any>(webHook, JSON.stringify(message), options).subscribe(res => {
console.log('res' + res);
return res;
}); // error here about json at 0 with ok response and 200 http
我在正确的Slack 频道中看到了通知,但由于我的 Angular 应用程序中有一个错误拦截器,因此错误导致我的 Angular 应用程序出现问题,非常感谢任何帮助。
错误拦截器.ts:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// console.log('request was intercepted by error');
return next.handle(req)
.pipe(
// Retry on failure
retry(2),
// Handle errors
catchError((error: HttpErrorResponse) => {
console.error(error);
let errorMessage = 'An unknown error occurred!';
if (error.error.message) {
errorMessage = error.error.message;
}
this.dialog.open(ErrorComponent, {data: {message: errorMessage}});
this.errorService.throwError(errorMessage);
return throwError(error);
}));
}
【问题讨论】:
-
您似乎正在尝试解析已经存在的 JSON 对象?可以加拦截代码吗?
-
@ApoorvaChikara 我已经添加了拦截器,如果我将拦截器全部移除,我仍然会收到错误,所以认为它不是来自这里
标签: angular typescript http slack