首页 > 解决方案 > Slack API Angular Integration 200 错误并带有“OK 响应”

问题描述

我正在尝试创建一个Slack与我的应用程序通信的angular应用程序,我觉得好像我非常接近让它工作但是我收到以下错误:

安慰

以下是我在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频道中看到了通知,但是因为我的角度应用程序中有一个错误拦截器,所以错误导致我的角度应用程序出现问题,非常感谢任何帮助。

错误拦截器.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);
  }));

}

标签: angulartypescripthttpslack

解决方案


答案是从服务器正确返回的,但是返回时很可能会返回一个字符串,这会导致它为假。从服务器正确返回信息的示例:

烘焙:

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}

推荐阅读