restangular icon indicating copy to clipboard operation
restangular copied to clipboard

[QUESTION] Is there a way to override the global error interceptor from individual calls

Open atinsood opened this issue 10 years ago • 4 comments

I am setting a global error interceptor in my config function but I was hoping that I can override this is if needed on per request basis.

If I understand correctly the response will always be intercepted by the error interceptor that I have in the config and then by the interceptor I have on my individual call.

I was wondering if there is a way to reverse this.

The only other possible solution I can think of is to not set the global error interceptor and individually set interceptor of each of the restangular calls.

atinsood avatar Sep 19 '15 05:09 atinsood

I'm curious about this too as it seems a more natural approach.

I read http://stackoverflow.com/questions/28010548/restangular-how-to-override-error-interceptors but it doesn't really address the underlying issue. The most intuitive approach is for global error interceptor to trigger last (i.e. Specific_ErrorHandler (if Exists) > ErrorInterceptor > End).

btiernay avatar Jan 06 '17 19:01 btiernay

See https://github.com/mgonto/restangular/issues/566

btiernay avatar Jan 06 '17 19:01 btiernay

Without having investigated this at all, my intuition has a hard time imagining how the error interceptors could be executed after the context specific error handlers. I agree that it perhaps would make more sense, but given the nature of the promise mechanism and the data flow being somewhat like this:

CALL: context -> restangular -> $http -> HTTP request
REPONSE: HTTP response -> $http -> restangular -> "internal" error interceptor -> context

I don't see how the proposed flow would be possible, not to mention clean and tidy.

Any suggestions in form of PRs are most welcome, though!

bostrom avatar Jan 07 '17 14:01 bostrom

Sorry, I'm not really familiar with the code base, but wouldn't it be a matter of changing the order of these statements:

https://github.com/mgonto/restangular/blob/master/src/restangular.js#L1287-L1292

That is to say, invoke

deferred.reject(response)

before

.every(config.errorInterceptors, function(cb) {
  return cb(response, deferred, okCallback) !== false;
})

btiernay avatar Jan 07 '17 16:01 btiernay