From 7746299791c2ff3aada405559943ee1db28af534 Mon Sep 17 00:00:00 2001 From: Parag More Date: Wed, 26 Aug 2026 16:57:10 +0530 Subject: [PATCH] fix: return 409 instead of 502 when a pushed action fails Work-order and spare-part handlers responded with 502 when a pushed action came back with errors, but Cloudflare replaces origin 502 bodies with its own error page, so the ERR_ reason (for example ERR_NO_AVAILABLE_IP when the subnet has no free lease) never reached the client. These are failures reported by the workers for a request that conflicts with the current system state, so return 409 with the ERR_ message intact. --- workers/lib/server/handlers/spare.parts.handlers.js | 2 +- workers/lib/server/lib/work.orders.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/workers/lib/server/handlers/spare.parts.handlers.js b/workers/lib/server/handlers/spare.parts.handlers.js index 1727d68..226b7d8 100644 --- a/workers/lib/server/handlers/spare.parts.handlers.js +++ b/workers/lib/server/handlers/spare.parts.handlers.js @@ -115,7 +115,7 @@ async function updateSparePart (ctx, req) { const partPushErrors = _pushErrors(partResults) if (partPushErrors.length) { const err = new Error(`ERR_PART_UPDATE_PUSH_FAILED:${partPushErrors.join(',')}`) - err.statusCode = 502 + err.statusCode = 409 err.detail = { stage: 'part', partAction: null, workOrderAction: null } throw err } diff --git a/workers/lib/server/lib/work.orders.js b/workers/lib/server/lib/work.orders.js index 2bea4a3..b55f315 100644 --- a/workers/lib/server/lib/work.orders.js +++ b/workers/lib/server/lib/work.orders.js @@ -44,7 +44,7 @@ function assertActionApplied (results, errCode) { const errors = (results || []).flatMap(r => r?.errors || []) if (errors.length) { const err = new Error(`${errCode}:${errors.join(',')}`) - err.statusCode = 502 + err.statusCode = 409 throw err } } @@ -69,7 +69,7 @@ async function assertActionsExecuted (ctx, req, errCode) { .flatMap(target => (target.calls || []).map(call => call.error).filter(Boolean))) if (!errors.length) return const err = new Error(`${errCode}:${errors.join(',')}`) - err.statusCode = 502 + err.statusCode = 409 throw err }