Skip to content

Bug: vendors mutations throw raw Error for not-found and conflict cases — REST API and UI get opaque 500s instead of actionable 4xx/ConvexError #2004

Closed

Description

@yannickmonney

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):

  1. Call updateVendor with a vendorId that does not exist → throw new Error('Vendor not found') → opaque Server Error in console.
  2. Call updateVendor with an email already used by another vendor → throw new Error('Vendor with email … already exists') → opaque Server Error.
  3. Call deleteVendor with a non-existent vendorId → 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 ConvexError so withRestAuth's ConvexError→HTTP mapping (lines 293–314 of lib/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').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedbugpriority: mediumservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions