Error handling

Should execute be used to correctly throw errors, or is it the same in this case?
const result = await context.db
    .delete(user)
    .where(and(eq(user.role, 'student'), eq(user.id, userId)))
    .execute();

if (!result.success && result.error) throw new Error(result.error);

await context.db
    .delete(user)
    .where(and(eq(user.role, 'student'), eq(user.id, userId)));
Was this page helpful?