Skip to content

Commit

Permalink
Fix unsupported headers and status of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
André Coelho committed Apr 3, 2017
1 parent 726252a commit fbb34b3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/interceptors/oauth-interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function oauthInterceptor($q, $rootScope, OAuthToken) {
return config;
},
responseError: function(rejection) {
if (!rejection) {
return $q.reject(rejection);
}

// Catch `invalid_request` and `invalid_grant` errors and ensure that the `token` is removed.
if (400 === rejection.status && rejection.data &&
('invalid_request' === rejection.data.error || 'invalid_grant' === rejection.data.error)
Expand All @@ -29,7 +33,7 @@ function oauthInterceptor($q, $rootScope, OAuthToken) {
// The token isn't removed here so it can be refreshed when the `invalid_token` error occurs.
if (401 === rejection.status &&
(rejection.data && 'invalid_token' === rejection.data.error) ||
(rejection.headers('www-authenticate') && 0 === rejection.headers('www-authenticate').indexOf('Bearer'))
(rejection.headers && rejection.headers('www-authenticate') && 0 === rejection.headers('www-authenticate').indexOf('Bearer'))
) {
$rootScope.$emit('oauth:error', rejection);
}
Expand Down

0 comments on commit fbb34b3

Please sign in to comment.