-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Documentation for beforeError has incorrect usage of response.body #446
Comments
also need to read responses from a json API in response.body if an error. Doesn't seem to be automaticlaly parsed? |
I solved it like this @rlwhatley3 . Not ideal, considering the reason to use (my error message is potentially a collection of errors, so that's the only reason it's a
|
@sindresorhus is the fix impossible to add in library itself? Seems like this issue has been open since almost 3 months. I would love to contribute. |
This is a mistake in the documentation. I think that example was written with the assumption that we would automatically parse the body and the The example could be updated to something like this: hooks: {
beforeError: [
async error => {
const {response} = error;
if (response) {
const { message } = await response.json();
error.name = 'GitHubError';
error.message = `${message} (${response.statusCode})`;
}
return error;
}
]
} In the future, I think it would make sense for us to have something like |
Documentation States:
but the response.body is a readable stream.
I need to be able to get the response body for failed calls, to render error message that are set on the backend via a json api. The only way to do this currently is to set the throwHttpErrors to false AND not use .json, which leads the code to have to check returned objects responses as a whole instead of as a json, and to check for specific fields etc to determine if its in error.
The text was updated successfully, but these errors were encountered: