Repository navigation
breaking: pass all errors through handleError, update the function contract - #16664
elliott-with-the-longest-name-on-github merged 22 commits into
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/0841f3722b7ffd0c2658ed729af4824e89d1d025Open in |
🦋 Changeset detectedLatest commit: 0841f37 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| Alongside the `event`, the hook receives a `kind` discriminant that tells you where the error came from, and the `error` itself: | ||
|
|
||
| | `kind` | thrown by | `error` | defaults to | | ||
| | -------------- | ----------------------------------- | -------------------------------------------------------------------- | -------------------------------------------- | | ||
| | `'expected'` | [`error(...)`](@sveltejs-kit#error) | the error body, which matches [`App.Error`](types#Error) | the error body itself | | ||
| | `'unexpected'` | your code, or code it calls | the thrown value, which may contain information unsafe to expose | `{ status: 500, message: 'Internal Error' }` | | ||
| | `'framework'` | SvelteKit — 404s, 405s, 413s... | `{ status, message }`, where `message` is safe text like `Not Found` | that same `{ status, message }` | |
There was a problem hiding this comment.
Yeah it's kinda weird, I wonder if there's a way to get the header formatting better...
|
looks like some tests need updating |
cd174e9 to
c75edb4
Compare
Rich-Harris
left a comment
There was a problem hiding this comment.
LGTM aside from the naming
| } | ||
| ``` | ||
|
|
||
| The object you return becomes the body of an [expected error](errors#Expected-errors), which then passes through [`handleError`](hooks#handleError) with `kind: 'app'`. |
There was a problem hiding this comment.
we should probably update the headings on this page to 'App errors' and 'Unknown errors'

closes #16413
Two substantive changes:
handleErrornow handles all errorserrorhelperThese are passed into
handleErroras akind, errorunion, where the type oferrordepends on thekind:unknownApp.Error{ message: string, status: string }handleErrormust returnApp.Error, thoughstatusandmessageare optional (the framework will generate them automatically if you don't provide them). So the following is valid for just logging:But you can also: