kit
kit copied to clipboard
Export `ActionFailure` to allow `instanceof`
Describe the problem
I have some shared logic for parsing user input, but it's not that convenient to deal with success/error types.
Describe the proposed solution
ActionFailure is a class, but SvelteKit exposes it as an interface. It would be nice to simply return fail() and do instanceof ActionFailure:
function parse(value: T | null) {
if (!value) {
return fail(400, { message: 'Too high' })
}
// ...
return value
}
// Action:
const result = parse('test')
if (result instanceof ActionFailure) {
return result
}
Alternatives considered
- Creating my own class
- Returning a result type like
{ value: T, error: null } | { value: null, error: string } - Use the
Errorclassmessageas an intermediate, if I only need an error string
Importance
nice to have
Additional Information
No response