Skip to content

Commit 63c7486

Browse files
authored
Fix inconsistent cross origin error handling (#667)
* Fix inconsistent cross origin error handling * change any error to a super big error message description
1 parent a167f1c commit 63c7486

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/web-auth/cross-origin-authentication.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var windowHelper = require('../helper/window');
44
var objectHelper = require('../helper/object');
55
var RequestBuilder = require('../helper/request-builder');
66
var WebMessageHandler = require('./web-message-handler');
7+
var responseHandler = require('../helper/response-handler');
78

89
function CrossOriginAuthentication(webAuth, options) {
910
this.webAuth = webAuth;
@@ -70,7 +71,7 @@ CrossOriginAuthentication.prototype.login = function(options, cb) {
7071
error: 'request_error',
7172
error_description: JSON.stringify(err)
7273
};
73-
return cb(errorObject);
74+
return responseHandler(cb)(errorObject);
7475
}
7576
var popupMode = options.popup === true;
7677
options = objectHelper.blacklist(options, ['password', 'credentialType', 'otp', 'popup']);

test/web-auth/cross-origin-authentication.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
252252
response: {
253253
body: {
254254
error: 'any_error',
255-
error_description: 'any error'
255+
error_description: 'a super big error message description'
256256
}
257257
}
258258
});
@@ -267,7 +267,11 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
267267
anotherOption: 'foobar'
268268
},
269269
function(err) {
270-
expect(err).to.be.eql({ error: 'any_error', error_description: 'any error' });
270+
expect(err).to.be.eql({
271+
original: { error: 'any_error', error_description: 'a super big error message description' },
272+
code: 'any_error',
273+
description: 'a super big error message description'
274+
});
271275
expect(_this.webAuthSpy.authorize.called).to.be.eql(false);
272276
done();
273277
}
@@ -300,8 +304,12 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
300304
},
301305
function(err) {
302306
expect(err).to.be.eql({
303-
error: 'request_error',
304-
error_description: '{"some":"error"}'
307+
original: {
308+
error: 'request_error',
309+
error_description: '{"some":"error"}'
310+
},
311+
code: 'request_error',
312+
description: '{"some":"error"}'
305313
});
306314
expect(_this.webAuthSpy.authorize.called).to.be.eql(false);
307315
done();

0 commit comments

Comments
 (0)