Loading bar interceptor throws exception when a transformResponse throws exception.
Opened this issue · 11 comments
v0.8.0
Regarding the discussion at #50. I ran into this because my transformResponse was throwing an error (due the response being some error output and not the expected output). I had a very case specific transform because it was part of a $resource.
When an exception occurs in transformResponse the response seems to get rejected with only the error message (not the http response). Therefore rejection.config
is always null/undefined in this scenario. Because of how angular loading bar works I was forced to manually check the status of the response and wrap potential breaking code in an if block to stop the exception occurring.
So when a transformResponse throws an exception, angular loading bar throws with the error in #50. I don't think that is a ideal. I see you need the config to do some stuff but perhaps it should only throw if rejection is falsey and if config is also falsey just fail silently?
'responseError': function(rejection) {
if (!rejection || !rejection.config) {
$log.error('Broken interceptor detected: Config object not supplied in rejection:\n https://github.com/chieffancypants/angular-loading-bar/pull/50');
return $q.reject(rejection);
}
I agree and have the same problem!
How did you exactly workaround this?
Here is my code:
.factory('appendTransform', function ($http) {
var appendTransform = function(transform) {
var defaults = $http.defaults.transformResponse;
// We can't guarantee that the default transformation is an array
defaults = angular.isArray(defaults) ? defaults : [defaults];
// Append the new transformation to the defaults
return defaults.concat(transform);
};
return appendTransform;
})
and
$http({method: 'GET', url: 'http://myserverurl', data: myData, transformResponse: appendTransform(fetchFromServerParser.getData) });
Thank you in advance!
Is there any way to push append a transform response only if the response code is 200, in angular? Instead of always appending it
the same problem
the same problem
the same
+1
+1
v0.9.0 too.
I think maintainer has abandoned this package
+1
This project is dead!