1

Is it possible to implement a "responseError" interceptor for $http service that would trigger only if there is no specific failure handler defined elsewhere for the given http promise?

So that in case of an error in the response, the following expression $http.get(...).success(...) will execute some code in the interceptor, while the following one $http.get(...).success(...).error(...) won't.

1 Answer 1

1

You can use a decorator:

app.config(function($provide) {
    $provide.decorator('$exceptionHandler', function($delegate, $injector) {
        return function $broadcastingExceptionHandler(ex, cause) {
            $delegate(ex, cause);
            $injector.get('$rootScope').$broadcast('exception', ex, cause);
        }
    });
});

This example will catch all exceptions though, but you can examine the error and handle it appropriately.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.