Skip to content

Commit

Permalink
docs: clarify some +error.svelte behavior (#8485)
Browse files Browse the repository at this point in the history
* docs: clarify some +error.svelte behavior

closes #7875
closes #8349

* Apply suggestions from code review

Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
  • Loading branch information
dummdidumm and Rich-Harris authored Jan 13, 2023
1 parent 40464ef commit 6870a0f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions documentation/docs/20-core-concepts/10-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ If an error occurs during `load`, SvelteKit will render a default error page. Yo

SvelteKit will 'walk up the tree' looking for the closest error boundary — if the file above didn't exist it would try `src/routes/blog/+error.svelte` and then `src/routes/+error.svelte` before rendering the default error page. If _that_ fails (or if the error was thrown from the `load` function of the root `+layout`, which sits 'above' the root `+error`), SvelteKit will bail out and render a static fallback error page, which you can customise by creating a `src/error.html` file.

If the error occurs inside a `load` function in `+layout(.server).js`, the closest error boundary in the tree is an `+error.svelte` file _above_ that layout (not next to it).

If no route can be found (404), `src/routes/+error.svelte` (or the default error page, if that file does not exist) will be used.

> `+error.svelte` is _not_ used when an error occurs inside [`handle`](/docs/hooks#server-hooks-handle) or a [+server.js](#server) request handler.
You can read more about error handling [here](/docs/errors).
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/30-advanced/25-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ You can customise the fallback error page by adding a `src/error.html` file:
SvelteKit will replace `%sveltekit.status%` and `%sveltekit.error.message%` with their corresponding values.
If the error instead occurs inside a `load` function while rendering a page, SvelteKit will render the [`+error.svelte`](/docs/routing#error) component nearest to where the error occurred.
If the error instead occurs inside a `load` function while rendering a page, SvelteKit will render the [`+error.svelte`](/docs/routing#error) component nearest to where the error occurred. If the error occurs inside a `load` function in `+layout(.server).js`, the closest error boundary in the tree is an `+error.svelte` file _above_ that layout (not next to it).
The exception is when the error occurs inside the root `+layout.js` or `+layout.server.js`, since the root layout would ordinarily _contain_ the `+error.svelte` component. In this case, SvelteKit uses the fallback error page.
Expand Down

0 comments on commit 6870a0f

Please sign in to comment.