restangular
restangular copied to clipboard
Interceptors not working?
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?
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.
This sounds like a bug. Can you provide a live example on Plunkr?