HttpInterceptor catchError获取响应内容类型

时间:2018-09-15 22:33:56

标签: angular6

我正在尝试在HttpInterceptor catchError中从服务器获取响应的内容类型。

我的拦截器是 导出类HttpErrorHandlerService实现HttpInterceptor {

export class HttpErrorHandlerService implements HttpInterceptor {

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req)
      .pipe(catchError(err => {
        // get contenttype here
        return empty();
      }));      
  }
}  

我需要这样做,因为有时我的服务器将使用需要解析的JSON数据进行响应,有时它只是一条简单的文本错误消息。
err.headers似乎为空

0 个答案:

没有答案
相关问题