This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Composition of error handler + interceptors should be more flexible #4013
Closed
Description
For ngResource
there are 3 places to handle HTTP errors:
- Interceptor on global level defined via
$httpProvider
(further global interceptor), - Interceptor defined for every action of every
$resource
(further local interceptor), - Error handler specified within the call of the action (as a second error handler argument).
The demo of all 3 ways is here: http://plnkr.co/edit/wWGzbEUj1Gr2KwmxTrmx
There are 2 problems with this:
- The order is kind of illogical: global interceptor -> error handler -> local interceptor;
- There is no way to let know from the error handler that interceptors should not handle that error anymore.
Now the use-case: I want to make user aware of every failed request. But:
- Some of them I'll handle in my controllers where I call the action. Let's say show very nice error message, or implement the fall-back logic;
- Some of them are resource specific. Like if I have
User
resource and it returns me 404 not found, I always want to redirect somewhere; - And finally all other errors. I want no silent failures to happen and I write a global interceptor which will handle all error responses (if they are not handled yet) and show growl-style notification with HTTP code and error message from server.
Currently it's only possible to talk from error handler to local interceptor by setting some response._handled = true
(not really nice), but global interceptor is always executed first and thus completely out of control.
The solution could be:
- Add a an order attribute to interceptors. Error handler can have some default value and interceptors get order assigned relative to that;
- Some way of preventing interceptors of being called from the error handler.