Skip to content

Commit

Permalink
return Unknown error for anything other than Network error. Some linting
Browse files Browse the repository at this point in the history
  • Loading branch information
cheedep committed Apr 6, 2018
1 parent 7eb3970 commit 6d518c5
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions packages/amazon-cognito-identity-js/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Client {
const headers = {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': `AWSCognitoIdentityProviderService.${operation}`,
'X-Amz-User-Agent': this.userAgent
'X-Amz-User-Agent': this.userAgent,
};

const options = {
Expand Down Expand Up @@ -63,31 +63,29 @@ export default class Client {
return callback(error);
})
.catch(err => {
let code = 'UnknownError', error = {};
let error = { code: 'UnknownError', message: 'Unkown error' };

// first check if we have a service error
if ( response && response.headers && response.headers.get('x-amzn-errortype') ) {
if (response && response.headers && response.headers.get('x-amzn-errortype')) {
try {
code = (response.headers.get('x-amz-errortype')).split(':')[0];
error = {
code,
name: code,
statusCode: response.status,
message: (response.status) ? response.status.toString() : null,
};
} catch( error ) {
// pass through so it doesn't get swallowed if we can't parse it
}
// otherwise check error
} else if ( err instanceof Error ) {
const code = (response.headers.get('x-amz-errortype')).split(':')[0];
error = {
code: err.name,
name: err.name,
message: err.message
code,
name: code,
statusCode: response.status,
message: (response.status) ? response.status.toString() : null,
};
} catch (ex) {
// pass through so it doesn't get swallowed if we can't parse it
}
// otherwise check if error is Network error
} else if (err instanceof Error && err.message === 'Network error') {
error = {
code: err.name,
name: err.name,
message: err.message,
};
// finally case will return 'UnknownError'
} else {
error = { code };
}
return callback(error);
});
Expand Down

0 comments on commit 6d518c5

Please sign in to comment.