Catching ConvexError on the frontend
Has anyone tried to get the convex error message in the front-end? For example doing a mutation (Inside the mutation I throw a ConvexError but the message I receive in the front when I catch it is a big string with a lot of data, not just the messag).
4 Replies
What's your catching code look like, and how are you turning the error object into a string?
I am using a try/catch block. The error being catch is a ConvexError. And when I do error.message, I get something like this:
ConvexError: [CONVEX M(invitations:createInvitation)] [Request ID: 508b65e3043a038d] Server Error
Uncaught ConvexError: User not found
at handler (../convex/invitations.ts:46:10)
Called by client
And the Idea would be to get the "User not found"
This is to invite users to something. And there are multiple possible error (not found, already a member, etc...)
the field is
error.data
, not error.message
https://docs.convex.dev/functions/error-handling/application-errors#application-error-data-payloadApplication Errors | Convex Developer Hub
If you have expected ways your functions might fail, you can either return
Thanks