Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(authentication): include response object in 'Token not found in …
Browse files Browse the repository at this point in the history
…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
indfnzo committed Mar 6, 2017
1 parent 0af1c63 commit d5131ca
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/authentication.js
Expand Up @@ -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;
}
Expand Down

0 comments on commit d5131ca

Please sign in to comment.