handling error from mutation in client
how best to handle an error during a mutation on the front end
I want to display an error when a duplicate entry fails to be added
10 Replies
Either
or
The thing to do is probably set some state
If it's a ConvexError you can count on e.data being what you passed into the ConvexError on the server.
https://docs.convex.dev/functions/error-handling/#errors-in-mutations
https://docs.convex.dev/functions/error-handling/application-errors
Application Errors | Convex Developer Hub
If you have expected ways your functions might fail, you can either return
Error Handling | Convex Developer Hub
There are four reasons why your Convex
the errors I throw (ConvexError and Error) will not be accessible on the client in prod? So I can't use them to transport data?
So I have to use
return "<blah blah blah>"
to transport data?ConvexError is accessible on the client in prod
Oh, ok, I thought this because of this line here

that line demonstrates that a ConvexError and its data are accessible on the client
in this case the data payload was of type { message: string } but it could just as well be { flavor: string, servings: number }
@ballingt what do you mean by set some state? where?
say a
const [mutationError, setMutationError] = useState();
then use that to render something different
Thank you that makes sense