solid-router: If a function wrapped in action throws some error it should be possible to catch it.
Describe the bug
Let’s consider this example:
const myAction = action(() => throw new Error("Some error"));
// somewhere in a component
const doMyAction = useAction(myAction);
doMyAction().then(() => {
// this function will always be executed despite the fact that the action failed.
console.log('Action resolves without any error');
}, (error) => {
// this function will never catch an error
console.error('An error occured');
});
This error relates to this line: https://github.com/solidjs/solid-router/blob/main/src/data/action.ts#L97 Perhaps, handler should check the argument type (to preserve the current possibility to throw redirect or revalidate) and throw an error if the argument is not solid-related thing.
Your Example Website or App
see description
Steps to Reproduce the Bug or Issue
run this code
const myAction = action(() => throw new Error("Some error"));
// somewhere in a component
const doMyAction = useAction(myAction);
doMyAction().then(() => {
// this function will always be executed despite the fact that the action failed.
console.log('Action resolves without any error');
}, (error) => {
// this function will never catch an error
console.error('An error occured');
});```
### Expected behavior
Error handler should handle errors.
### Screenshots or Videos
_No response_
### Platform
any
### Additional context
_No response_
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Comments: 20 (8 by maintainers)
Yeah I just went with my original proposal.
.errorfield and throw when not form. Tell me if this works for you well. Released in 0.13.0