Property 'catch' does not exist on type 'ObservableHttpEventany' ANGULAR 6

1

I created an interceptor to catch all the errors using angle 6, but catch returns this message.

 intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>{
    return next.handle(req)
        .catch((error, caught) => {

         (....)

           return Observable.throw(errorObj);
        }) as any;
  };
}

I researched a lot and found that in angle 6 should be used o:

import { catchError } from 'rxjs/operators';
import { throwError,  Observable } from 'rxjs';

But things do not work out here either. I also tried the:

import 'rxjs/add/operator/catch';

But the angle says: Module not found: Error: Can not resolve 'rxjs / add / operator / catch' in '...'

    
asked by anonymous 11.06.2018 / 15:13

1 answer

0

I resolved by changing the code and leaving it this way:

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>{
    return next.handle(req)
        .pipe(
        catchError((error, caught) => {
          (...)
        }
     return observableThrowError(errorObj);
        })) as any;

link

    
11.06.2018 / 15:34