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