1

My interceptor is not working (not triggered). Any error on my part? Sorry I'm still a rookie :(

module myApp {
export class HttpConfigurator {
    public configure(httpProvider: ng.IHttpProvider) {
        console.log(httpProvider);
        console.log(httpProvider.interceptors[0]);

        httpProvider.interceptors.push([
            '$location',
            '$q',
            '$log',
            ($location: ng.ILocationService, $q: ng.IQService, $log: ng.ILogService) => {
                return promise => promise.then(
                    response => { console.log(response.status); return response; },
                    response => {
                        console.log(response.status);
                        if (response.status >= 500) {

                        }

                        if (response.status === 401 || response.status === 403) {
                            $location.path('/403');
                            return $q.reject(response);
                        } else {
                            return $q.reject(response);
                        }
                    });
            }]);
    }
}

}

Note: Previously this is working when it was in javascript. When I converted it to typescript then the problem started.

1

1 Answer 1

0

I don't see promise defined anywhere. Note that due to the simplicity of interceptors I just use a function + factory:

app.factory('appHttpInterceptor', [function () {
    return {
        response: function (response) {
            if (typeof (MiniProfiler) != 'undefined') {
                var ids = response.headers()['x-miniprofiler-ids'];
                if (ids) {
                    MiniProfiler.fetchResultsExposed($.parseJSON(ids));
                }
            }

            return response;
        }
    };
}]);

And not use a class.

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.