Javascript 如何截获非JSON的响应

Javascript 如何截获非JSON的响应,javascript,angular,typescript,Javascript,Angular,Typescript,我正在使用Angular 5.1.0,试图读取服务器发送的文件,作为对GET请求的响应 我正在这样做: getImage(imageUrl: string) { const httpOptions = { headers: new HttpHeaders({ 'Authorization': 'Basic ' + this.authService.getBasicAuthString(), resourceType: 'blob'

我正在使用Angular 5.1.0,试图读取服务器发送的文件,作为对GET请求的响应

我正在这样做:

  getImage(imageUrl: string) {
    const httpOptions = {
      headers: new HttpHeaders({
        'Authorization': 'Basic ' + this.authService.getBasicAuthString(),
        resourceType: 'blob'
      })
    };
    return this.http.get<File>(imageUrl, httpOptions);
  }
如前所述,我想使用(),但在替换return Observable.throw(event)时出现以下错误返回(req)

ERROR in src/app/shared/parser.interceptor.ts(16,5): error TS2322: Type 'Observable<{} | HttpProgressEvent | HttpSentEvent | HttpHeaderResponse | HttpResponse<any> | Http...' is not assignable to type 'Observable<HttpEvent<any>>'.
  Type '{} | HttpProgressEvent | HttpSentEvent | HttpHeaderResponse | HttpResponse<any> | HttpUserEvent<a...' is not assignable to type 'HttpEvent<any>'.
    Type '{}' is not assignable to type 'HttpEvent<any>'.
      Type '{}' is not assignable to type 'HttpUserEvent<any>'.
        Property 'type' is missing in type '{}'.
src/app/shared/parser.interceptor.ts(31,14): error TS2304: Cannot find name 'of'.

您是否从rxjs导入了
catch
操作符

import 'rxjs/add/operator/catch'

如果您使用的是Rxjs 5.5,请遵循此

可能重复的好捕获,我将用以下问题更新我的答案:)
ERROR in src/app/shared/parser.interceptor.ts(16,5): error TS2322: Type 'Observable<{} | HttpProgressEvent | HttpSentEvent | HttpHeaderResponse | HttpResponse<any> | Http...' is not assignable to type 'Observable<HttpEvent<any>>'.
  Type '{} | HttpProgressEvent | HttpSentEvent | HttpHeaderResponse | HttpResponse<any> | HttpUserEvent<a...' is not assignable to type 'HttpEvent<any>'.
    Type '{}' is not assignable to type 'HttpEvent<any>'.
      Type '{}' is not assignable to type 'HttpUserEvent<any>'.
        Property 'type' is missing in type '{}'.
src/app/shared/parser.interceptor.ts(31,14): error TS2304: Cannot find name 'of'.
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/catch'