0

I am currently working in a fork of this example project

It implements a global error handler and an HTTP interceptor. That's fine, but I would like to know if it is possible to have more control on how to handle my errors on a per case basis:

  • if an HTTP call handles its own errors, do not use HTTP interceptor
  • Use HTTP interceptors for all other cases
  • also, be able to decide when I want to make an HTTP call providing my own handler and when not to.

Ideally, I would like to have something like

    //most cases (global error handling)
    myHttpService.post("api url", payload).subscribe(....)
    //custom handler
    myHttpService.post("api url", payload).subscribe(..., (err) =>{})
    //custom handler could also be  
    myHttpService.post("api url", payload).subscribe(...).catchError(...)
    //or also 
    myHttpService.post("api url", payload, errHandlerFunction).subscribe(...)

is it possible to have both global error handler, interceptor AND per-call handling?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
user5328504
  • 734
  • 6
  • 21
  • Certainly not using what you've shown, because that information isn't available. The post invocation, for example, has no idea how many of the callbacks are being passed to the downstream subscription (and there may be more than one). If you want to bypass interceptors for certain calls, see e.g. https://stackoverflow.com/questions/46469349/how-to-make-an-angular-module-to-ignore-http-interceptor-added-in-a-core-module. – jonrsharpe Oct 15 '19 at 21:33
  • You would have to pass some information as part of the request. There's an issue opened for that. Currently, a workaround is to pass information using a header. See https://github.com/angular/angular/issues/18155 – JB Nizet Oct 15 '19 at 21:36
  • @jonrsharpe my post() calls are not directly http calls. myService is actually a feature/shared service which exposes sutff like login() and getSales() which in the end, a few layers down do an actual http call. So I control the subscriptions to each call. Im also using ngrx in some cases, but the question still applies – user5328504 Oct 15 '19 at 21:40

0 Answers0