QzCuriousQ
Convex Community3w ago
1 reply
QzCurious

Make ArgumentValidationError a class and expose it so a client can identify it

🎁Feature Request
Though it's not a "meant to be" usage of convex. I'm using convex as a database and having a oRPC/Node.js app connects to it. I don't use convex client.

Feature Request


Make
ConvexClient
query
throw identifiable error when
ArgumentValidationError
heppened. So caller of it can handle it.

The setup


convex query function
import { v } from "convex/values";
export const getProduct = query({
  args: { storeId: v.id("stores") },
  handler: () => {}
})


I'm calling convex like this, and it throws error
const convex = new ConvexClient(env.CONVEX_URL);
await convex.query(api.products.getProduct, { storeId: "invalid-id"})


What happened


The error is a generic
Error
I believe. I can identify it by
err.message.includes("ArgumentValidationError")
. But it only works for development. Production error is like
Error: [CONVEX Q(products:getProduct)] [Request ID: df413dad71c22523] Server Error
.

Development Error:
[CONVEX Q(products:getProduct)] [Request ID: 0750239d5647b2fb] Server Error
ArgumentValidationError: Found ID "jh7an9ffvzx6jaa4fadxnk7zz180zr1q" from table
productCategories
, which does not match the table name in validator
v.id("products")
.Path: ._id
Called by client

Production Error:
[CONVEX Q(products:getProduct)] [Request ID: 1fc968523fcb6eaf] Server Error
Called by client

What I wanna do (in case you need to know)


I want catch that error, in middleware of oRPC, and provide 400 response with sensible message for my client so they know they're passing the wrong
id
.
Was this page helpful?