MCPcopy
hub / github.com/nuxt/nuxt / createError

Function createError

packages/nuxt/src/app/composables/error.ts:72–98  ·  view source on GitHub ↗
(error: string | Error | Partial<NuxtError<DataT>>)

Source from the content-addressed store, hash-verified

70
71/** @since 3.0.0 */
72export const createError = <DataT = unknown>(error: string | Error | Partial<NuxtError<DataT>>) => {
73 if (typeof error !== 'string' && (error as Partial<NuxtError<DataT>>).statusText) {
74 error.message ??= (error as Partial<NuxtError<DataT>>).statusText
75 }
76
77 const nuxtError: NuxtError<DataT> = createH3Error<DataT>(error)
78
79 Object.defineProperty(nuxtError, NUXT_ERROR_SIGNATURE, {
80 value: true,
81 configurable: false,
82 writable: false,
83 })
84
85 // #34165 - TODO: remove in Nuxt 5 when statusCode/statusMessage are removed
86 Object.defineProperty(nuxtError, 'status', {
87 // eslint-disable-next-line @typescript-eslint/no-deprecated
88 get: () => nuxtError.statusCode,
89 configurable: true,
90 })
91 Object.defineProperty(nuxtError, 'statusText', {
92 // eslint-disable-next-line @typescript-eslint/no-deprecated
93 get: () => nuxtError.statusMessage,
94 configurable: true,
95 })
96
97 return nuxtError
98}

Callers 15

setupFunction · 0.90
validate.tsFile · 0.90
setupFunction · 0.90
entry.tsFile · 0.90
handleVueErrorFunction · 0.90
setupFunction · 0.90
_fetchComponentFunction · 0.90
renderStubMessageFunction · 0.90
interval.tsFile · 0.90
abortNavigationFunction · 0.90
buildAsyncDataFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…