Skip to content

Commit

Permalink
fix(useFetch): parse body even if status is not ok (vueuse#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismail Gjevori authored and antfu committed Jul 5, 2021
1 parent 84c5580 commit be5964e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core/useFetch/index.ts
Expand Up @@ -326,14 +326,15 @@ export function useFetch<T>(url: MaybeRef<string>, ...args: any[]): UseFetchRetu

let responseData = await fetchResponse[config.type]()

// see: https://www.tjvantoll.com/2015/09/13/fetch-and-errors/
if (!fetchResponse.ok)
throw new Error(fetchResponse.statusText)

if (options.afterFetch)
({ data: responseData } = await options.afterFetch({ data: responseData, response: fetchResponse }))

data.value = responseData as any

// see: https://www.tjvantoll.com/2015/09/13/fetch-and-errors/
if (!fetchResponse.ok)
throw new Error(fetchResponse.statusText)

responseEvent.trigger(fetchResponse)
resolve(fetchResponse)
})
Expand Down

0 comments on commit be5964e

Please sign in to comment.