Repository navigation
Description
Area
services/platform/convex/vendors/mutations.ts (client-callable mutationWithRLS) and services/platform/convex/vendors/internal_mutations.ts (called by the REST API via withRestAuth).
Note: issue #1993 covers duplicate-add (createVendor duplicate email/externalId on POST). This issue covers the remaining raw Error throws: not-found guards and update/delete duplicate-conflict checks, which were omitted from #1993.
Steps to reproduce
UI path (mutations.ts):
- Call
updateVendorwith avendorIdthat does not exist →throw new Error('Vendor not found')→ opaque Server Error in console. - Call
updateVendorwith an email already used by another vendor →throw new Error('Vendor with email … already exists')→ opaque Server Error. - Call
deleteVendorwith a non-existentvendorId→ same opaque error.
REST API path (internal_mutations.ts via PATCH /api/v1/vendors/:id or DELETE /api/v1/vendors/:id):
4. PATCH a vendor with a duplicate email or externalId → throw new Error(...) falls to the generic 500 catch in withRestAuth (line 318 of lib/rest/helpers.ts) instead of being mapped to a 409 via ConvexError.
5. PATCH or DELETE a non-existent vendor → same 500 instead of 404.
Expected
- Client-callable mutations throw
ConvexError({ code: 'VENDOR_NOT_FOUND' })/ConvexError({ code: 'DUPLICATE_EMAIL' })etc. → no uncaught Server Error. - Internal mutations (REST path) throw the same structured
ConvexErrorsowithRestAuth's ConvexError→HTTP mapping (lines 293–314 oflib/rest/helpers.ts) can return 404/409 instead of 500.
Actual
All paths use throw new Error(...). withRestAuth only maps ConvexError to 4xx; plain Error falls through to a 500.
Evidence
services/platform/convex/vendors/mutations.ts (client-callable):
:40—throw new Error('Vendor not found')(updateVendor):73—throw new Error('Vendor with email … already exists')(updateVendor):77—throw new Error('Vendor with external ID … already exists')(updateVendor):99—throw new Error('Vendor not found')(deleteVendor)
services/platform/convex/vendors/internal_mutations.ts (REST path):
:99—throw new Error('Vendor not found')(updateVendor):105—throw new Error('Vendor not found')(cross-tenant guard,updateVendor):138—throw new Error('Vendor with email … already exists')(updateVendor):142—throw new Error('Vendor with external ID … already exists')(updateVendor):170—throw new Error('Vendor not found')(deleteVendor):176—throw new Error('Vendor not found')(cross-tenant guard,deleteVendor)
The createVendor duplicate errors in internal_mutations.ts:41 and :56 are also raw Error but were already noted in #1993.
Notes
withRestAuth in services/platform/convex/lib/rest/helpers.ts:293 maps ConvexError codes to HTTP statuses via httpStatusForConvexCode. Add VENDOR_NOT_FOUND → 404, DUPLICATE_EMAIL → 409, DUPLICATE_EXTERNAL_ID → 409 to that map, and replace the throw new Error(...) calls with throw new ConvexError({ code: '...' }) (import ConvexError from 'convex/values').
Activity
fix(platform): throw ConvexError for vendor not-found and conflict ca…