restangular icon indicating copy to clipboard operation
restangular copied to clipboard

Interceptors not working?

Open arjan123 opened this issue 11 years ago • 2 comments

In my app config I've the following default interceptor

 RestangularProvider.setBaseUrl("/api/model");
    RestangularProvider.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
        var newResponse = response;
        if (newResponse.data.data)
            return newResponse.data.data;
        return newResponse;
    });

Now I've also another interceptor defined in a service

app.factory('PublicRestService', PublicRestService);
PublicRestService.$inject = ['Restangular'];
function PublicRestService(Restangular) {
    return Restangular.withConfig(function(RestangularConfigurer) {
        RestangularConfigurer.setBaseUrl('/public');
        //won't work.!!!!! Here we want to uniform the response (as with the default provider)
        RestangularConfigurer.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
            var newResponse = response;
            if (newResponse.data.data)
                return newResponse.data.data;
            return newResponse;
        });
    });
}

The default injector (first one) does work fine but if I use the service (second) the interceptor won't go off.

Am I doing something wrong here?

arjan123 avatar Nov 08 '14 11:11 arjan123

I second that. Trying to do exactly the same. If both interceptors are in the global config, then they both run, but that's the only way.

JaffParker avatar Jan 04 '16 16:01 JaffParker

This sounds like a bug. Can you provide a live example on Plunkr?

daviesgeek avatar Jun 18 '16 00:06 daviesgeek