Skip to content

Order creation returns HTTP 500 instead of a 4xx for ordinary validation failures #884

Closed

Description

@itsbkm

Summary

POST /api/orders (main/routes/orders.ts) throws plain new Error(...) (no .statusCode) for several ordinary, expected failure conditions inside the order-creation transaction. The route's catch-all handler defaults any error without a .statusCode to HTTP 500 and returns a generic "Internal server error" — so these are misreported as server bugs instead of the specific, actionable client errors they actually are.

Where

  • main/routes/orders.ts:600 — throw new Error(\Product ${item.product_id} not found`)when a cart item references a product no longer present inproducts` (e.g. deleted/archived after the POS cached its menu).
  • main/routes/orders.ts:612 — throw new Error(\Invalid price for ${product.name}...`)whenproduct.price` is negative/non-finite.
  • main/routes/orders.ts:621 — throw new Error(\Invalid add-on quantity...`)` for a non-integer/negative add-on quantity.

All three fall through to the generic branch at main/routes/orders.ts:737-745:

} catch (error: any) {
  console.error('[Orders] Create error:', error);
  const statusCode = error.statusCode || 500;
  ...
  res.status(statusCode).json({ error: error.statusCode ? error.message : "Internal server error" });
}

For comparison, InventoryServiceError/SupplyServiceError/UnitConversionError and the tax/charge helpers all correctly attach .statusCode and are handled as 4xx.

Real-world impact

Two production support tickets from the same store (order.place.rejected, HTTP 500) were filed 42 seconds apart — the merchant retried the same order and hit the same opaque 500 twice, with no actionable message. The most likely cause given the diagnostics (stage order_place, category bug) is a stale POS-cached cart referencing a product that no longer exists, which should have surfaced as a clear 404, not a generic server error.

Fix

Attach .statusCode (404 for missing product, 400 for invalid price/add-on quantity) to these three throws, consistent with the existing pattern used elsewhere in the same file.

Verification note

There's no server-side stack trace or log capture for the specific failing request (console.error only reaches the Electron main-process console/app.log, and the diagnostic ping sent to the backend, reportOrderCreateFailure, only reports stage/status/item_count — not the error itself). Confirming this is the actual root cause for these two tickets specifically would need the merchant's app.log; the code-level bug is real and worth fixing regardless.

Activity

  1. added a commit that references this issue on Sep 26, 2026
    bfffef9
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions