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(nuxt): wrap caught asyncData error in createError #24093

Merged
merged 6 commits into from Nov 8, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/nuxt/src/app/composables/asyncData.ts
Expand Up @@ -212,7 +212,11 @@ export function useAsyncData<
// If this request is cancelled, resolve to the latest request.
if ((promise as any).cancelled) { return nuxt._asyncDataPromises[key] }

asyncData.error.value = error
const nuxtError = createError(error)

nuxt.payload._errors[key] = nuxtError

asyncData.error.value = nuxtError as DataE
danielroe marked this conversation as resolved.
Show resolved Hide resolved
asyncData.data.value = unref(options.default!())
asyncData.status.value = 'error'
})
Expand All @@ -221,10 +225,7 @@ export function useAsyncData<

asyncData.pending.value = false
nuxt.payload.data[key] = asyncData.data.value
if (asyncData.error.value) {
// We use `createError` and its .toJSON() property to normalize the error
nuxt.payload._errors[key] = createError(asyncData.error.value)
}

delete nuxt._asyncDataPromises[key]
})
nuxt._asyncDataPromises[key] = promise
Expand Down