Nuxt/docs/3.api/3.utils/set-response-status.md

1006 B

title description links
setResponseStatus setResponseStatus sets the statusCode (and optionally the statusMessage) of the response.
label icon to size
Source i-simple-icons-github https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts xs

Nuxt provides composables and utilities for first-class server-side-rendering support.

setResponseStatus sets the statusCode (and optionally the statusMessage) of the response.

::callout setResponseStatus can only be called in the Nuxt context. ::

const event = useRequestEvent()

// event will be undefined in the browser
if (event) {
  // Set the status code to 404 for a custom 404 page
  setResponseStatus(event, 404)

  // Set the status message as well
  setResponseStatus(event, 404, 'Page Not Found')
}

::callout In the browser, setResponseStatus will have no effect. ::

:read-more{to="/docs/getting-started/error-handling"}