ibrahimyaacob
ibrahimyaacob4mo ago

tanstack mutation onError doesnt handle convex error properly

I expect that on the client side, i would just render the message, not the whole error stack
No description
No description
No description
6 Replies
ballingt
ballingt4mo ago
@ibrahimyaacob try error.data.message, that should be what you pass in see https://docs.convex.dev/functions/error-handling/application-errors
ibrahimyaacob
ibrahimyaacobOP4mo ago
hey @ballingt i just figured that it works if i do it like this
No description
ibrahimyaacob
ibrahimyaacobOP4mo ago
kinda hoping that convex would automatically handle the type of the thrown error i probably expecting to high lol
ballingt
ballingt4mo ago
Say more, automatically handle how? @ibrahimyaacob do you want to set a global handler and always toast or something?
ibrahimyaacob
ibrahimyaacobOP4mo ago
im saying i dont want to add that ConvexErr type on the onError callback or maybe im such a noob on error handling haha
ballingt
ballingt4mo ago
Ah got it, actually careful since there are other errors you could get here too! ConvexErrors are the only ones that will have messages attached, but other built-in errors can throw here too and they're just normal errors. In dev they'll have stack traces and messages and all but in prod they're more like Error("server error") so as not to leak information from the backend whereas a ConvexError always has the message / data attached

Did you find this page helpful?