Slack API Angular 与 'OK response' 的集成 200 错误
Slack API Angular Integration 200 error with 'OK response'
我正在尝试创建一个与我的 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 应用程序出现问题,任何帮助是非常感谢。
错误-interceptor.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);
}));
}
答案是从服务器 returned 正确的,但是当一个字符串 returns 时,它很可能会被 returned,这将导致它是错误的。
来自服务器的正确 return 信息示例:
烘焙:
return OK('wellcome'); /// return {status:200,ok:false}
// This is a mistake and you should send the information as follows
string data='wellcome';
return Ok(data) // {status:200,ok:true}
解决方案是将请求的 resonsetype
更改为 'text'
,因为它期待 JSON
响应。
this.http.post(webHook, JSON.stringify(message), {headers, responseType: 'text'}).subscribe(res => {
console.log('res' + res);
return res;
});
我正在尝试创建一个与我的 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 应用程序出现问题,任何帮助是非常感谢。
错误-interceptor.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);
}));
}
答案是从服务器 returned 正确的,但是当一个字符串 returns 时,它很可能会被 returned,这将导致它是错误的。 来自服务器的正确 return 信息示例:
烘焙:
return OK('wellcome'); /// return {status:200,ok:false}
// This is a mistake and you should send the information as follows
string data='wellcome';
return Ok(data) // {status:200,ok:true}
解决方案是将请求的 resonsetype
更改为 'text'
,因为它期待 JSON
响应。
this.http.post(webHook, JSON.stringify(message), {headers, responseType: 'text'}).subscribe(res => {
console.log('res' + res);
return res;
});