gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

intercept errors #134

Closed joshikeerti closed 7 years ago

joshikeerti commented 7 years ago

Is there a way to intercept errors? Currently httpInterceptor.request() and httpInterceptor.response() intercept the request and response, but if we need to intercept errors, is there a method that can help do this?

gund commented 7 years ago

How about catch() operator?

httpInterceptorService.response().addInterceptor(res => res.catch(e => {
  console.log('Caught http error:' + e);
  return Observable.empty(); // Recover from error
}));
gund commented 7 years ago

I'm going to close this assuming my example helped you.