Repository: auth0/auth0.js
Pull request #939 (2019-05-22 02:33:59)

Fix checksession error format
fix https://github.com/auth0/auth0.js/issues/932

### Changes

The error was being thrown in the 'raw' format, instead of going through our response handler which formats the error in a specific way. This PR fixes that.


Patch:
diff --git a/src/web-auth/index.js b/src/web-auth/index.js
index cc8d5ae..62a9cad 100644
--- a/src/web-auth/index.js
+++ b/src/web-auth/index.js
@@ -1,12 +1,13 @@
 import IdTokenVerifier from 'idtoken-verifier';
+import qs from 'qs';
 
 import assert from '../helper/assert';
 import error from '../helper/error';
-import qs from 'qs';
 import PluginHandler from '../helper/plugins';
 import windowHelper from '../helper/window';
 import objectHelper from '../helper/object';
 import SSODataStorage from '../helper/ssodata';
+import responseHandler from '../helper/response-handler';
 import TransactionManager from './transaction-manager';
 import Authentication from '../authentication';
 import Redirect from './redirect';
@@ -480,7 +481,7 @@ WebAuth.prototype.checkSession = function(options, cb) {
   assert.check(cb, { type: 'function', message: 'cb parameter is not valid' });
 
   params = objectHelper.blacklist(params, ['usePostMessage', 'tenant', 'postMessageDataType']);
-  this.webMessageHandler.run(params, cb);
+  this.webMessageHandler.run(params, responseHandler(cb, { forceLegacyError: true }));
 };
 
 /**


Test patch:
diff --git a/test/web-auth/web-auth.test.js b/test/web-auth/web-auth.test.js
index 39c52c5..7290ec6 100644
--- a/test/web-auth/web-auth.test.js
+++ b/test/web-auth/web-auth.test.js
@@ -2408,6 +2408,14 @@ describe('auth0.WebAuth', function() {
       });
       this.auth0.checkSession({}, function(err) {
         expect(err).to.be.eql({
+          original: {
+            error: 'origin_mismatch',
+            error_description:
+              "The redirectUri's origin (some-other-origin) should match the window's origin (https://test-origin.com)."
+          },
+          code: 'origin_mismatch',
+          description:
+            "The redirectUri's origin (some-other-origin) should match the window's origin (https://test-origin.com).",
           error: 'origin_mismatch',
           error_description:
             "The redirectUri's origin (some-other-origin) should match the window's origin (https://test-origin.com)."
@@ -2459,6 +2467,12 @@ describe('auth0.WebAuth', function() {
       });
       this.auth0.checkSession({ state: 'foobar' }, function(err, data) {
         expect(err).to.be.eql({
+          original: {
+            error: 'timeout',
+            error_description: 'Timeout during executing web_message communication'
+          },
+          code: 'timeout',
+          description: 'Timeout during executing web_message communication',
           error: 'timeout',
           error_description: 'Timeout during executing web_message communication'
         });
@@ -2476,6 +2490,12 @@ describe('auth0.WebAuth', function() {
       });
       this.auth0.checkSession({}, function(err, data) {
         expect(err).to.be.eql({
+          original: {
+            error: 'the-error',
+            error_description: 'error description'
+          },
+          code: 'the-error',
+          description: 'error description',
           error: 'the-error',
           error_description: 'error description'
         });