Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new 500.astro error prop #8392

Merged
merged 17 commits into from
Jun 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion src/content/docs/en/basics/astro-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,56 @@ Files with the `.html` file extension can be placed in the `src/pages/` director

## Custom 404 Error Page

For a custom 404 error page, you can create a `404.astro` or `404.md` file in `/src/pages`.
For a custom 404 error page, you can create a `404.astro` or `404.md` file in `src/pages`.
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

This will build to a `404.html` page. Most [deploy services](/en/guides/deploy/) will find and use it.

## Custom 500 Error Page
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

For a custom 500 error page, you can create a `500.astro` in `src/pages`.

:::caution
Once deployed, Astro will only use `500.astro` when using `output: 'hybrid'` or `output: 'server'`.
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
:::

If an error occur in this file, it will default to the host 500 error page.
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

### Retrieve The Error
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

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

`500.astro` accepts an error as a prop. It can be anything so make sure to handle it properly:
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

```astro title="src/pages/500.astro"
---
interface Props {
error: unknown
}

const { error } = Astro.props
---

<div>{error instanceof Error ? error.message : 'Unknown error'}</div>
```

### Usage In Development
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

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

You can use your custom 500 error page in development by setting the `ASTRO_CUSTOM_500` environment variable to `'true'`. For example using a `.env` file:
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

```ini title=".env"
ASTRO_CUSTOM_500=true
```

Or inline:
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

```sh
ASTRO_CUSTOM_500=true astro dev
```

If an error occur in this file, it will default to the error overlay.
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

## Page Partials

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