-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export ActionFailure
to allow instanceof
#12611
Comments
Does adding a check such as below solve your issue? if ('status' in result && typeof result.status === 'number' && result.status >= 400) {
return result;
} or simply throw the function parse(value: T | null) {
if (!value) {
throw fail(400, { message: 'Too high' })
}
// ...
return value
}
// Action:
try {
const result = parse('test')
} catch (error) {
if ('status' in error) {
return error as ActionFailure;
}
} Using |
No, I don't feel like those are any simpler than the workarounds I mentioned. The second is also not type safe so I would highly discourage using that |
We already have |
Isn't it just as convenient and more performant to call |
oops it's called
I don't think performance matters here. What matters more is consistency, and we decided a while ago we want this to exposed via functions (gives more flexibility for the underlying implementation) and so it makes sense to keep it that way for new additions. |
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 simplyreturn fail()
and doinstanceof ActionFailure
:Alternatives considered
{ value: T, error: null } | { value: null, error: string }
Error
classmessage
as an intermediate, if I only need an error stringImportance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: