JacobLinCool / JacobLinCool/sveltekit-api
Feature Request: Support JSON in error bodies
- Dominant language
- TypeScript
- Stars
- 56
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
It would be great to have structured, machine-readable JSON error responses instead of the default SvelteKit HTML error page when an error is thrown.
Currently, if an error is thrown within an API route handler (e.g., `throw Error[401];`), the consumer receives an HTML page with the error details. This is not suitable for API consumers who expect predictable JSON payloads for all responses, including errors.
Is there a particular reason why this is not supported?
Simply returning a JSON object that indicates an error (e.g., `return { error: true, message: "..." }`) doesn't work either because `sveltekit-api` validates the return value against the defined Zod output schema.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing error handling for SvelteKit API route handlers and the Zod output-schema validation described in the issue. Determine how thrown errors currently become HTML responses and how a consistent JSON error shape should interact with schema validation. Done means API consumers receive predictable JSON error responses for thrown errors without breaking successful response validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100