I am using AngularJS v1.2.16 with Restangular v1.4.0 and would like to know if it is possible to override ErrorInterceptor. If so, how? if not, how can I work with him?
I configured the Interceptor error as follows:
RestangularProvider.setErrorInterceptor( function ( response ) { if ( response.status == 401 ) { dialogs.error("Unauthorized - Error 401", "You must be authenticated in order to access this content.") .result.then( function () { $location.path("/login"); }); } else {
then in another place I make a POST call with error handling.
function saveApple( apple ) { Restangular.all("apple/save").post( apple ).then( function ( response ) { console.log("Saved"); }, function ( response ) {
I understand that my “second” error handler is not called because I am returning false to ErrorInterceptor .
But how can I do this? I have many “REST operations” in my application, and only a few of them, I want to adjust the behavior when something goes wrong.
So far I have been thinking about what ErrorInterceptor return true needs to be done, and for all other REST operations I will copy the same error handler (more general). But that would be the last thing I would do.
Right now, flow as follows:
If possible, I want it to be like this: (Only for certain methods - not for all).
- ErrorInterceptor> Especific_ErrorHandler (if exists)> End.
it can also be like this:
- Especific_ErrorHandler (if exists)> ErrorInterceptor> End.
In any case, it works for me.
Literature:
https://github.com/mgonto/restangular#seterrorinterceptor https://github.com/mgonto/restangular#how-can-i-handle-errors
Thank Advance