Skip to content

Commit

Permalink
Merge pull request #217 from barillax/protect_against_null_errors
Browse files Browse the repository at this point in the history
fix(validate-token): gracefully handle empty data response
  • Loading branch information
booleanbetrayal committed Sep 28, 2015
2 parents 2e543a6 + aff3d0e commit 3b384f2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/ng-token-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ angular.module('ng-token-auth', ['ipCookie']).provider('$auth', function() {
$rootScope.$broadcast('auth:validation-error', data);
return _this.rejectDfd({
reason: 'unauthorized',
errors: data.errors
errors: data != null ? data.errors : ['Unspecified error']
});
};
})(this));
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-token-auth.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ng-token-auth.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ angular.module('ng-token-auth', ['ipCookie'])

@rejectDfd({
reason: 'unauthorized'
errors: data.errors
errors: if data? then data.errors else ['Unspecified error']
})
)
else
Expand Down
18 changes: 18 additions & 0 deletions test/test/unit/ng-token-auth/token-handling.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,21 @@ suite 'token handling', ->
$auth.validateUser()
$timeout.flush()
assert.equal(null, $auth.retrieveData('auth_headers'))

suite 'empty response', ->
setup ->
$auth.getConfig().forceValidateToken = true
$httpBackend
.expectGET('/api/auth/validate_token')
.respond(401, undefined)

dfd = $auth.validateUser()

$httpBackend.flush()

test 'promise should be rejected without error', (done) ->
dfd.catch(->
assert true
done()
)
$timeout.flush()

0 comments on commit 3b384f2

Please sign in to comment.