Permalink
Browse files

feat(authentication): include response object in 'Token not found in …

…response' errors

Before throwing the 'Token not found in response' error, the entire response is added as a key to the error. This allows clients to read the server response directly and display necessary information accordingly.

Partially resolves #332 for API servers that return a valid response code on errors.
  • Loading branch information...
jemhuntr committed Mar 4, 2017
1 parent 0af1c63 commit d5131cae4107ad77615ea6d627a3c7bbab0cb024
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/authentication.js
@@ -221,14 +221,28 @@ export class Authentication {
const tokenRootData = tokenRoot && tokenRoot.split('.').reduce((o, x) => o[x], responseTokenProp);
const token = tokenRootData ? tokenRootData[tokenName] : responseTokenProp[tokenName];
if (!token) throw new Error('Token not found in response');
if (!token) {
// if the token is not found in the response,
// throw an error along with the response object as a key
let error = new Error('Token not found in response');
error.responseObject = response;
throw error;
}
return token;
}
const token = response[tokenName] === undefined ? null : response[tokenName];
if (!token) throw new Error('Token not found in response');
if (!token) {
// if the token is not found in the response,
// throw an error along with the response object as a key
let error = new Error('Token not found in response');
error.responseObject = response;
throw error;
}
return token;
}

0 comments on commit d5131ca

Please sign in to comment.