Property 'catch' does not exist on type 'Observable<Httpevent<any>>' ANGULAR 6

Asked

Viewed 531 times

1

I created an Interceptor to catch all errors using angular 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 did a lot of research and found that at angle 6 the:

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

Things don’t even work that way around here, though. I also tried the:

import 'rxjs/add/operator/catch';

But the angular says: Module not found: Error: Can’t resolve 'rxjs/add/Operator/catch' in '...'

  • 2
  • comments there q mark as solved.

  • no, I put the solution down. There was a change in rxjs to add .pipe. But the q m mandate m manual helped to find this solution.

1 answer

1

  • Noob, I can’t mark your comment as resolved. I think q s you answer I will get.

  • You already answered with the solution, it would be interesting if you could explain how you solved the problem, if someone has the same problem in the future.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.