P

add-status-to-error-handling

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

This codemod improves error handling in SvelteKit by updating the way errors are returned in the load function. In SvelteKit 1, errors were handled inconsistently, often missing the status property or failing to trigger the handleError hook. SvelteKit 2 standardizes error handling by automatically including the status and message properties in error responses.

Change Summary

In SvelteKit 1, errors were returned with just the error property.
In SvelteKit 2, errors are now returned with both error and status properties, ensuring consistent error handling and making it easier to manage different HTTP statuses.
This codemod ensures that all errors returned from the load function are compatible with SvelteKit 2’s enhanced error handling.

Example

Before

ts

After

ts

Ready to contribute?

Build your own codemod and share it with the community.