Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

mcbouslog
Copy link
Contributor

@mcbouslog mcbouslog commented Mar 10, 2017

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.

@@ -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');
Copy link
Contributor Author

@mcbouslog mcbouslog Mar 10, 2017

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).
Copy link
Contributor

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;
}
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

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.

@mcbouslog mcbouslog closed this Mar 14, 2017
@eatyourgreens eatyourgreens deleted the refactor-json-api-client-error-handling branch August 7, 2018 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants