-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] edit error handling for object with status and response #61
Conversation
@@ -6,22 +6,21 @@ var apiClient = new JSONAPIClient(config.host + '/api', { | |||
'Accept': 'application/vnd.api+json; version=1', | |||
}, { | |||
beforeEveryRequest: function() { | |||
console.log('using local panoptes-client'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove, keeping while linking dependencies via GitHub branches.
@@ -33,19 +32,25 @@ var apiClient = new JSONAPIClient(config.host + '/api', { | |||
} else { | |||
errorMessage = 'Unknown error (bad response body)'; | |||
} | |||
} else if (response.text.indexOf('<!DOCTYPE') !== -1) { | |||
} else if (error.response.text.indexOf('<!DOCTYPE') !== -1) { | |||
// Manually set a reasonable error when we get HTML back (currently 500s will do this). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have the status code in the response, why are we sniffing the response body to test for a 500 error?
error.message = errorMessage; | ||
} | ||
|
||
throw error; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you call throw with something that isn't an instance of Error?
if (response.body.error_description) { | ||
errorMessage += ' ' + response.error_description; | ||
if (typeof error.response.body === 'object') { | ||
if (error.response.body.error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error.response.body.error
is pretty convoluted, and confusing, here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors should maybe follow the JSON API spec for error objects.
Not ready for merge, creating for discussion.
This is the 2nd PR to be merged in relation to improving API error handling.
1st to be merged would be the related PR in
json-api-client
, which contains more context and questions.