Ashutosh BindA
Convex Community6mo ago
2 replies
Ashutosh Bind

Convex error handling best practices

I am new to convex, and looked up the relevant error handling docs.

There are some Expected errors, and there could be convex-specific errors (network errs, etc)

I had some questions regarding error retries and how to handle them

export const createCourse = mutation({
    args: {
        title: v.string(),
        description: v.string(),

    },
    handler: async (ctx, args) => {
        const userId = await getUserId(ctx);

        try {
            const course = await ctx.db.insert("course", {
                title: args.title,
                description: args.description,
                ownerId: userId,
                isPublished: false,
            });

            return course;
        } catch (error) {
            throw new ConvexError({
                status: 500,
                message: "Error creating course",
            })
        }
    }
})

Note: the db query is used inside of a try catch

if I handle a public mutation as this, wont the db errors now classify as my Application(expected) errors as well, if so, what's the best way to handle it, just let the db calls be outside of try-catches?
Was this page helpful?