Satendra
Satendra10mo ago

How to access the Convex Error Message

Hi EveryOne, Right i am working on a problem and i need to access the the Convex Error message(User exceeded the trial limit) that i am passing from backend, so that i can do some basic operations on client side. So, it would be great if someone can help me. Thanks
No description
No description
No description
9 Replies
Satendra
SatendraOP10mo ago
Thanks but, how can read i this error on client side Actually i want to check if i am getting this error and based on that i have to open a modal. So if you could help me with that.
Michal Srb
Michal Srb10mo ago
If you scroll down the doc, it explains how to read the error on the client: https://docs.convex.dev/functions/error-handling/application-errors#handling-application-errors-on-the-client
Application Errors | Convex Developer Hub
If you have expected ways your functions might fail, you can either return
Satendra
SatendraOP10mo ago
Thanks but i am reading undefined when consoling the errorMessage Am i doing something wrong
No description
No description
Michal Srb
Michal Srb10mo ago
Use
console.log(err)
console.log(err)
Satendra
SatendraOP10mo ago
Thanks for helping me. I was able found the problem . So instead of using this err.data as { message: string }).message which is giving me undefined. I should have used err.data since i am sending just a message not a object with message field.
DaRealPheyee
DaRealPheyee10mo ago
you can also use the .include method to see if the error you are looking for is in the error message. It will be something like: try{ // Your code here } catch(error) { if(error.message.includes("User exceeded the trial limit")) { // Do something. Maybe open a modal. } else { console.log(error) } }
Michal Srb
Michal Srb10mo ago
@DaReal This will not work in production, because the message will be redacted: https://docs.convex.dev/functions/error-handling/#differences-in-error-reporting-between-dev-and-prod
Error Handling | Convex Developer Hub
There are four reasons why your Convex
DaRealPheyee
DaRealPheyee10mo ago
Oh! Wow...Thanks for letting me know. I will put that in mind.

Did you find this page helpful?