angular-loading-bar icon indicating copy to clipboard operation
angular-loading-bar copied to clipboard

Loading bar interceptor throws exception when a transformResponse throws exception.

Open worldspawn opened this issue 8 years ago • 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);
          }

worldspawn avatar May 16 '16 05:05 worldspawn

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!

LeleDev avatar Apr 14 '17 15:04 LeleDev

Is there any way to push append a transform response only if the response code is 200, in angular? Instead of always appending it

LeleDev avatar Apr 14 '17 15:04 LeleDev

the same problem

damsorian avatar May 19 '17 01:05 damsorian

the same problem

fedorovsky avatar Jun 06 '17 09:06 fedorovsky

the same

corehook avatar Jun 20 '17 09:06 corehook

+1

pokono avatar Oct 15 '17 02:10 pokono

+1

saad-bhutto avatar Dec 06 '17 04:12 saad-bhutto

v0.9.0 too.

@faceleg @darlanmendonca

frekele avatar Dec 27 '17 18:12 frekele

I think maintainer has abandoned this package

anurbol avatar Jan 13 '18 23:01 anurbol

+1

uweDuesing avatar Feb 15 '18 21:02 uweDuesing

This project is dead!

frekele avatar Feb 15 '18 21:02 frekele