Skip to content

Commit

Permalink
fix: status should be changed to success after data has been changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3xysteak committed Jul 30, 2024
1 parent cd57e49 commit 89eb969
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions src/core/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,29 @@ export function createUseFetch(defaultOptions: UseFetchOptions<any> = {}) {
status.value = 'pending'
pending.value = true

data.value = await $fetch<T, R>(toValue(req), {
...ctx.options$fetch,
...Object.fromEntries(
Object.entries(toValue(watchOptions)).map(([k, v]) => [k, toValue(v)]),
),
onRequest(content) {
ctx.resolveBody(content)
ctx.options$fetch?.onRequest?.(content)
},
onRequestError(content) {
status.value = 'error'
error.value = content.error
ctx.options$fetch?.onRequestError?.(content)
},
onResponse(content) {
status.value = 'success'

ctx.options$fetch?.onResponse?.(content)
},
onResponseError(content) {
status.value = 'error'
error.value = content.error ?? null
ctx.options$fetch?.onResponseError?.(content as any)
},
})
try {
data.value = await $fetch<T, R>(toValue(req), {
...ctx.options$fetch,
...Object.fromEntries(
Object.entries(toValue(watchOptions)).map(([k, v]) => [k, toValue(v)]),
),
onRequest(content) {
ctx.resolveBody(content)
ctx.options$fetch?.onRequest?.(content)
},
onRequestError(content) {
status.value = 'error'
error.value = content.error
ctx.options$fetch?.onRequestError?.(content)
},
})

status.value = 'success'
}
catch (_error) {
status.value = 'error'
error.value = (_error as any) ?? null
}

pending.value = false
}
Expand Down

0 comments on commit 89eb969

Please sign in to comment.