Replies: 3 comments 3 replies
-
Hi, yes, this is the expected behavior. |
Beta Was this translation helpful? Give feedback.
-
Hi @TheEdoRan, I think that would be nice to have, it would eliminate the need for the try/catch on the client code try {
const result = await testeAct.executeAsync({nome: "teste"})
console.log("result client", result)
} catch (error) {
console.error("error client try catch", error)
} Would be just. And all errors could be treated at the onError function const result = await testeAct.executeAsync({nome: "teste"})
console.log("result client", result) I created this customHook that does that import { useAction } from "next-safe-action/hooks";
export function useCustomAction<ActionInput, ActionOutput>(
action: any,
options?: any
) {
const actionHook = useAction(action, options);
const executeAsync = async (input: ActionInput) => {
try {
return await actionHook.executeAsync(input);
} catch (error) {
if (options?.onError) {
await options.onError(error as Error);
} else {
throw error;
}
}
};
return {
...actionHook,
executeAsync,
};
}```
|
Beta Was this translation helpful? Give feedback.
-
I am trying to avoid to have to handle errors in different places, like having onErrors and try/catch. Like for network erros the server will not get them and it will blow on the try/catch. If this option still requires adding a try/catch, I don't think it is worth it. |
Beta Was this translation helpful? Give feedback.
-
Hi, first thank you for this lib, it is really helping.
When I rethrown an error at handleServerError, it is not handled by onError in client. Is this the intended behavior?
I was expecting to be able to get an onError on the client.
Nextjs 14.2.6 and next-safe-action 7.9.6
Here is my code:
action.ts
Client code
action client
Thanks
Beta Was this translation helpful? Give feedback.
All reactions