2022-10-06 09:15:30 +00:00
|
|
|
---
|
2023-10-18 10:59:43 +00:00
|
|
|
title: 'setResponseStatus'
|
2022-10-06 09:15:30 +00:00
|
|
|
description: setResponseStatus sets the statusCode (and optionally the statusMessage) of the response.
|
2023-10-18 10:59:43 +00:00
|
|
|
links:
|
|
|
|
- label: Source
|
|
|
|
icon: i-simple-icons-github
|
|
|
|
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
|
|
|
size: xs
|
2022-10-06 09:15:30 +00:00
|
|
|
---
|
2022-08-02 16:01:59 +00:00
|
|
|
|
|
|
|
Nuxt provides composables and utilities for first-class server-side-rendering support.
|
|
|
|
|
2022-10-06 09:15:30 +00:00
|
|
|
`setResponseStatus` sets the statusCode (and optionally the statusMessage) of the response.
|
2022-08-02 16:01:59 +00:00
|
|
|
|
|
|
|
```js
|
2023-03-31 14:02:26 +00:00
|
|
|
const event = useRequestEvent()
|
|
|
|
|
2022-08-02 16:01:59 +00:00
|
|
|
// Set the status code to 404 for a custom 404 page
|
2023-03-31 14:02:26 +00:00
|
|
|
setResponseStatus(event, 404)
|
2022-08-02 16:01:59 +00:00
|
|
|
|
|
|
|
// Set the status message as well
|
2023-03-31 14:02:26 +00:00
|
|
|
setResponseStatus(event, 404, 'Page Not Found')
|
2022-08-02 16:01:59 +00:00
|
|
|
```
|
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
::callout
|
2022-08-02 16:01:59 +00:00
|
|
|
In the browser, `setResponseStatus` will have no effect.
|
|
|
|
::
|
2023-10-18 10:59:43 +00:00
|
|
|
|
|
|
|
:read-more{to="/docs/getting-started/error-handling"}
|