diff --git a/package-lock.json b/package-lock.json index 151c7452..af34e057 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.22.0", + "version": "1.23.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b45f64f6..75738970 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.22.0", + "version": "1.23.0", "displayName": "TAO Core SDK", "description": "Core libraries of TAO", "homepage": "https://github.com/oat-sa/tao-core-sdk-fe#readme", diff --git a/src/core/request.js b/src/core/request.js index d1d95c5a..578865a3 100644 --- a/src/core/request.js +++ b/src/core/request.js @@ -58,10 +58,16 @@ const logger = loggerFactory('core/request'); */ const createError = (response, fallbackMessage, httpCode, httpSent) => { let err; - if (response && response.errorCode) { - err = new Error(`${response.errorCode} : ${response.errorMsg || response.errorMessage || response.error}`); - } else { - err = new Error(fallbackMessage); + if (response) { + const code = response.errorCode || response.code; + const message = response.errorMsg || response.errorMessage || response.error || response.message; + if (code && message) { + err = new Error(`${code} : ${message}`); + } else if (message) { + err = new Error(`${message}`); + } else { + err = new Error(fallbackMessage); + } } err.response = response; err.sent = httpSent; @@ -301,7 +307,7 @@ export default function request(options) { sent: xhr.readyState > 0, type: 'error', textStatus: textStatus, - message: errorThrown || __('An error occurred!') + message: errorThrown || xhr.statusText || __('An error occurred!') }; const enhancedResponse = Object.assign({}, responseExtras, response); diff --git a/test/core/request/test.js b/test/core/request/test.js index 989bb0a6..9ccdf8ab 100644 --- a/test/core/request/test.js +++ b/test/core/request/test.js @@ -397,7 +397,7 @@ define(['jquery', 'lodash', 'core/request', 'core/tokenHandler', 'core/jwt/jwtTo title: 'disconnected', url: '//offline', reject: true, - err: new Error('0 : timeout'), + err: new Error('timeout'), reuseToken: true } ]) @@ -522,7 +522,7 @@ define(['jquery', 'lodash', 'core/request', 'core/tokenHandler', 'core/jwt/jwtTo code: 0, sent: false, source: 'network', - message: '0 : timeout' + message: 'timeout' }, '//202': { code: 202,