Skip to content

Commit

Permalink
feat: new 500.astro error prop (#8392)
Browse files Browse the repository at this point in the history
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
  • Loading branch information
3 people committed Jun 19, 2024
1 parent 7fbcdbc commit 56bfa7f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/content/docs/en/basics/astro-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ If an error occurs rendering this page, your host's default 500 error page will

During development, if you have a `500.astro`, the error thrown at runtime is logged in your terminal, as opposed to being shown in the error overlay.

### `error`

<p><Since v="4.11.0" /></p>

`src/pages/500.astro` is a special page that is automatically passed an `error` prop for any error thrown during rendering. This allows you to use the details of an error (e.g. from a page, from middleware, etc.) to display information to your visitor.

The error prop's data type can be anything, which may affect how you type or use the value in your code:

```astro title="src/pages/500.astro"
---
interface Props {
error: unknown
}
const { error } = Astro.props
---
<div>{error instanceof Error ? error.message : 'Unknown error'}</div>
```

To avoid leaking sensitive information when displaying content from the `error` prop, consider evaluating the error first, and returning appropriate content based on the error thrown. For example, you should avoid displaying the error's stack as it contains information about how your code is structured on the server

## Page Partials

<p><Since v="3.4.0" /></p>
Expand Down

0 comments on commit 56bfa7f

Please sign in to comment.