JanStevens / angular-growl-2

growl-like notifications for angularJS projects
MIT License
285 stars 97 forks source link

Exception in interceptor if the response doesn't have data set #82

Open shoaibmerchant opened 9 years ago

shoaibmerchant commented 9 years ago

I am using the $http interceptor to log all server messages on growl. In one random tests, we had CORS disabled on the server so there was no response sent all which resulted in growl throwing an exception.

I traced it to this line 160 in growlFactory.js

 this.serverMessagesInterceptor = ['$q', 'growl', function ($q, growl) {
    function checkResponse (response) {
      if (response !== undefined && response.data[_messagesKey] && response.data[_messagesKey].length > 0) {
        growl.addServerMessages(response.data[_messagesKey]);
      }
    }

    return {
      'response': function (response) {
        checkResponse(response);
        return response;
      },
      'responseError': function (rejection) {
        checkResponse(rejection);
        return $q.reject(rejection);
      }
    };
  }];

In the if conditions if you add another condition to check response.data not null, it can solve this.

      if (response !== undefined && response.data !== null && response.data[_messagesKey] && response.data[_messagesKey].length > 0) {

I know this is a special case (CORS disabled) but it would be nice to have the plugin addressing all possible scenarios. Looking forward for an update on this.

Thanks for all your work done on growl-v2!

althaus commented 8 years ago

I'm getting the same issue with aborting pending requests on page exit.

flaviocysne commented 8 years ago

There was an update in 30 Apr 2015 that has added those checks.

Please, see if it's resolved and, if it is, close the issue.