From fbb34b38d1f7b8f1b9360c0908ffd7027d980a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Coelho?= Date: Mon, 3 Apr 2017 10:33:50 +0100 Subject: [PATCH] Fix unsupported `headers` and `status` of undefined --- src/interceptors/oauth-interceptor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interceptors/oauth-interceptor.js b/src/interceptors/oauth-interceptor.js index bbdcadb..b94be80 100644 --- a/src/interceptors/oauth-interceptor.js +++ b/src/interceptors/oauth-interceptor.js @@ -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) @@ -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); }