orders: fix the 42703 that broke EVERY order detail page

getOrderDetail joined order_merchant_cadence on merchant_entity_id. Migration
021 rekeyed that view to merchant_key (merchant_entity_id is NULL on ~9% of the
feed, and duplicate merchant entities split one shop's history); 027 and 029
moved order_feed and order_spend across, and this query was missed. Every
/orders/<key> request has since failed with

  column rec.merchant_entity_id does not exist

The reason nobody saw a 500 is the second half of this commit: the page
collapsed every failure into 'That order could not be found.' A server fault
wearing the costume of a data condition reads as an empty spine and gets
investigated in the wrong repo. The hook now carries the status and only a
genuine 404 says the order is missing.
This commit is contained in:
2026-08-12 17:10:13 +10:00
parent 9790b64e1d
commit 79940202f1
3 changed files with 40 additions and 3 deletions
+10 -1
View File
@@ -1243,7 +1243,16 @@ export function useOrderDetail(entityKey: string | null) {
staleTime: 60_000,
queryFn: async () => {
const res = await fetch(`/api/orders/${encodeURIComponent(entityKey!)}`);
if (!res.ok) throw new Error("Failed to load order");
if (!res.ok) {
// Carry the status. Collapsing every failure into one Error is how a
// 500 on this route rendered as "that order could not be found" on
// every single order for weeks — a server fault wearing the costume of
// a data condition, which reads as "the spine is empty" and gets
// investigated nowhere near the actual bug.
const err = new Error(res.status === 404 ? "Order not found" : "Failed to load order");
(err as Error & { status?: number }).status = res.status;
throw err;
}
return res.json();
},
});