fix(W2): graceful skip when customer link not yet filled (no crash)

When CP record is drafted with product set before customer,
the webhook fires with customerId=null -> now returns
skipWriteBack=true (routed to No-op) instead of throwing.
Record re-fires webhook properly once customer field is set.
This commit is contained in:
2026-08-23 02:41:54 +08:00
parent a907a85a57
commit 266a3442c8
2 changed files with 7 additions and 3 deletions
+5 -1
View File
@@ -38,7 +38,11 @@ const custProdId = $json.customerProductId;
// 1. re-fetch the CP record
const cp = await ncGet(`/api/v2/tables/${T_CUSTPROD}/records/${custProdId}`);
const customerId = linkId(cp.customer);
if (!customerId) throw new Error('CP has no customer link');
if (!customerId) {
// Gracefully skip when customer link not yet filled (CP record is being drafted).
// The webhook will re-fire when customer is set later.
return { json: { skipWriteBack: true, customerProductId: custProdId, reason: 'no customer link yet' } };
}
// 2. load all active CPs for this customer
const cps = await ncGet(`/api/v2/tables/${T_CUSTPROD}/records?where=(customer,eq,${customerId})&limit=1000`);