Skip to content

Tighten up error handling #11287

@dummdidumm

Description

@dummdidumm

Describe the problem

#11278 sent me down a rabbit hole of error handling once more. It occured to me that us throwing errors is not correct, strictly speaking. Someone could've enhanced the App.Error object which means that more properties than just message are required, and as such calling error with just a string is wrong.

Describe the proposed solution

Instead of using error, we distinguish between unforseen fatal errors and not-so-bad errors by expanding on what was introduced in #11131:

  • We create a NonFatalError with status and message (and NotFound introduced in that PR would go away)
  • handleError is called with those, too, but our fallback uses the message verbatim in that case (because we know it doesn't contain sensitive information)
  • We expose that class through @sveltejs/kit so people can do instanceof NonFatalError in handleError and inspect the status/message (would also make More information about error in HandleServerError #6774 more clear)/not send this to an error reporting service in that case
  • If NonFatalError is discovered, the status is not 500 but instead the one defined in the instance

Alternatives considered

Leave this as is and document this somewhere in the code base

Importance

would make my life easier

Additional Information

Putting this on the 2.0 milestone because if we change this it could be seen as a breaking change (things appearing in handleError differently)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions