runAfter is not throwing an error on the client
Hello, can't understand why error is not throwing to the client.
This is the pattern I'm trying to implement.
I can see the Error 'Called getCurrentUser without authentication present' logged in convex, but I can't get it in the front end. I'm using Next.js.
This is the pattern I'm trying to implement.
I can see the Error 'Called getCurrentUser without authentication present' logged in convex, but I can't get it in the front end. I'm using Next.js.
convex/customers.tsconvex/customers.tsexport const upsertCustomer = mutation({
args: customerArgs,
handler: async (ctx, args) => {
const organization = await getCurrentOrganization(ctx)
return await upsertCustomerWithFacturapi(ctx, {
...args,
organizationId: organization._id,
})
},
})
async function upsertCustomerWithFacturapi(
ctx: MutationCtx,
args: CustomerArgs,
): Promise<any> {
try {
return await ctx.scheduler.runAfter(
0,
api.customers_usenode.upsertCustomerWithFacturapi,
{
...args,
},
)
} catch (error) {
return {
error: error instanceof Error ? error.message : String(error),
}
}
}export const upsertCustomer = mutation({
args: customerArgs,
handler: async (ctx, args) => {
const organization = await getCurrentOrganization(ctx)
return await upsertCustomerWithFacturapi(ctx, {
...args,
organizationId: organization._id,
})
},
})
async function upsertCustomerWithFacturapi(
ctx: MutationCtx,
args: CustomerArgs,
): Promise<any> {
try {
return await ctx.scheduler.runAfter(
0,
api.customers_usenode.upsertCustomerWithFacturapi,
{
...args,
},
)
} catch (error) {
return {
error: error instanceof Error ? error.message : String(error),
}
}
}convex/customers_usenode.tsconvex/customers_usenode.ts'use node'
export const upsertCustomerWithFacturapi = action({
args: customerArgs,
handler: async (ctx, args) => {
const { customerData, organizationId, customerId } = args
const facturapiCustomerData = {
// object...
}
try {
const facturapi = await getFacturapiLiveInstance({ ctx })
} catch (error) {
return {
error: error instanceof Error ? error.message : String(error),
}
}
},
})'use node'
export const upsertCustomerWithFacturapi = action({
args: customerArgs,
handler: async (ctx, args) => {
const { customerData, organizationId, customerId } = args
const facturapiCustomerData = {
// object...
}
try {
const facturapi = await getFacturapiLiveInstance({ ctx })
} catch (error) {
return {
error: error instanceof Error ? error.message : String(error),
}
}
},
})convex/facturapi_usenode.tsconvex/facturapi_usenode.ts'use node'
export const getFacturapiLiveInstance = async ({
ctx,
}: {
ctx: ActionCtx
}): Promise<Facturapi> => {
try {
const currentUserOrganization = await ctx.runQuery(
internal.organizations.getOrganizationFacturapiKeys,
)
const facturapi = new Facturapi()
return facturapi
} catch (error) {
throw new Error('Error getting Facturapi instance')
}
}'use node'
export const getFacturapiLiveInstance = async ({
ctx,
}: {
ctx: ActionCtx
}): Promise<Facturapi> => {
try {
const currentUserOrganization = await ctx.runQuery(
internal.organizations.getOrganizationFacturapiKeys,
)
const facturapi = new Facturapi()
return facturapi
} catch (error) {
throw new Error('Error getting Facturapi instance')
}
}