This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #742, fixes #812, fixes #955, fixes #993, fixes #960
First off: I implemented this before I saw #1512 (comment). I'm not sure if it has any chance of getting merged, but I still wanted to share it. I need it for myself anyway, because I need more flexible error handling and I couldn't wait for Kit right now. :)
This PR adds support for custom error middleware. It allows you to define an error handler in
src/routes/_error.{js,ts}
like so:It also centralizes all Sapper handling. This means:
next(err)
also render a full error page when possible... and it makes the default error handling respect
err.status
(anderr.statusCode
), like both Express and Polka.This PR solves the same problem as #1512, but:
(err, req, res, next) => void
middleware already exists in Express/Polka and should be familiar to most users. This makes it easier to explain and makes it possible to reuse existing error handlers.src/routes/_error
file to be config 🙂)Before submitting the PR, please make sure you do the following
Tests
npm test
and lint the project withnpm run lint