Skip to content

Errors details

The rules, limits and messages behind the Errors guide. The signatures are under createError and the headings after it.

What the visitor sees

ErrorStatusMessage and data in production
thrown with createErrorits statusas you wrote them
any other, with a status or statusCode of 400 to 599that statusthe status text, such as "Conflict", and no data
any other500"Internal Server Error" and no data
a URL that nothing matches404
a path whose server routes do not take the method405, with an allow header
  • The same holds for the HTML and for the payload. In development the real message and the stack are shown.
  • At a handler's URL and at a URL that nothing matches, a request that prefers text/html gets the HTML error page. Any other gets JSON.
  • An error after the first part of a streamed page was sent cannot change the status.
  • createError with a status outside 400 to 599 makes a 500.
  • Nuxt's statusCode and statusMessage are not options (HAMUR_W3017). hamur migrate nuxt rewrites them.

Errors that skip a boundary

A route boundary catches what the route's load, middleware, meta.params, meta.validate, search schema and render throw. The error page answers for these instead:

  • a createError({ fatal: true })
  • an error of a layout or of the app root
  • a malformed path

A redirect, false and abortNavigation() are not errors, and no boundary catches them. A 404 takes the covering not-found component first, then a route boundary. page:error runs before a boundary renders, and in the browser app:error runs too.

notFoundMode

app.notFoundMode says what answers a URL that no page matches, with status 404.

ValueAnswer
"root" (default)app/pages/_not-found.<ext>, inside the app root and the default layout; without that file, the error page
"fuzzy"the deepest parent page or pathless layout whose path is a prefix of the URL, with the not-found component of its children in its Outlet; with no such page or component, as "root"

The prerendered 404.html is the root not-found component when the app has one.

Errors in the browser

CaseWhat happens
middleware throws, a load answers an error, a layout is unknownthe error page at the new URL
the code of a page cannot be loaded, as after a deploya full page load
an error while rendering that no ErrorBoundary catchesthe error page at the URL being rendered
an error outside a render, such as in Vue's event handlersthe page stays, except for a createError({ fatal: true })
showError(error)the error page at the current URL; the history does not change
showError(error) on the server, or while a navigation rendersthrows the error, so the error page answers for that URL
any successful navigationclears the error

The hooks page:error, app:error and app:error:cleared are in the list of app hooks. An app:error hook cannot change what the page shows. A hook that throws is logged, and the others still run.

ErrorBoundary

The props in each library are under ErrorBoundary. On the server, a part that throws renders its fallback into the HTML, and the page answers 200. The browser starts with that fallback, and reset does nothing on the server.

In React, a suspended child can fail after the first part of the page was sent. The browser then starts with the server's fallback. An ErrorBoundary inside that failed Suspense is rendered again in the browser.

Error and render handlers

Ruleerrorrender
runs forevery error the server answers, after the error hooksevery page, the error page included
does not run forcaptureError, a stream, waitUntil, the endpoints under /_hamur/a handler's route or a public file
returnsa Response, or undefined to keep the answera Response
hands over withnext(error?), so next(createError({ status: 404 })) turns your own error into a 404render(), once per request
  • The app's handler runs first, then each layer's by priority, then each module's. next and render reach the next one, and Hamur's own answer after the last.
  • A handler that throws or returns something else is logged once, and the next answer is used: the error handler of server/index.ts returned string; return a Response or undefined.
  • A value that is not a function fails when the server starts: error of server/index.ts must be a function from defineErrorHandler (got object).
  • An error the page throws rejects render(). A handler that catches it and returns a Response answers with that, and the error is still reported.
  • A streamed page stays streamed unless the render handler reads its body.

The types are under defineErrorHandler and defineRenderHandler.