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

fix(useFetch): parse body even if status is not ok #572

Merged
merged 1 commit into from Jun 29, 2021

Conversation

isgj
Copy link
Contributor

@isgj isgj commented Jun 10, 2021

fixes #553
fixes #526

While not yet clear what path we should take in order to have access to the response body when the status code is not ok I propose this PR.

@NoBrainSkull
Copy link

Looks fair enough to me. What do you think @wheatjs ?

@wheatjs
Copy link
Member

wheatjs commented Jun 21, 2021

I think this is good, maybe we can also pass the error to the responseData to the error as well?

@isgj
Copy link
Contributor Author

isgj commented Jun 22, 2021

Do you mean

if (!fetchResponse.ok) {
  const error = new Error(fetchResponse.statusText)
  error.data = responseData
  throw error
}

like suggested #526 (comment)

@antfu antfu changed the title Parse body even if status is not ok fix(useFetch): parse body even if status is not ok Jun 29, 2021
@antfu antfu merged commit ba2b11e into vueuse:main Jun 29, 2021
@isgj isgj deleted the body-ok-not-ok branch June 29, 2021 16:29
antfu pushed a commit to MinatoHikari/vueuse that referenced this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants