zidZ
Convex Community2y ago
7 replies
zid

Handling errors from convex

Hey Team, is there a better way to handle/throw convex errors to the client?
I have a particular setup for one part of my app where it would be very efficient if I could simply throw the error directly from the server. Here's the way I'm handling this now

  const handleUpdateSkill = async ({ type, skill }) => {
    try {
      await updateSkill({
        userId,
        type,
        skill,
      });
    } catch (error) {
      let errorMessage = error.message || "Cannot add more skills";

      // First, remove the known prefix if it's there
      const prefixToRemove = "[CONVEX M(arsenal:updateSkill)] Uncaught Error: ";
      errorMessage = errorMessage.replace(prefixToRemove, "");

      // Now, remove any trailing details after "at handler"
      errorMessage = errorMessage.split("\n")[0];

      toast.error(errorMessage);
    }
  };
Was this page helpful?