Skip to content

Commit

Permalink
Merge branch 'master' into rn-button-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanranz authored Jan 5, 2019
2 parents 5bdc9f8 + a7d0d19 commit 9a36d33
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions packages/amazon-cognito-identity-js/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,31 @@ export default class Client {
return callback(error);
})
.catch(err => {
// if cannot split the data
// default to return 'UnknownError' with the json data from response
let error = { code: 'UnknownError', message: 'Unknown error, the response body from fetch is: ' + responseJsonData};

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

0 comments on commit 9a36d33

Please sign in to comment.