fix(economic): fix validate() shape mismatch and restore exit(1) on fatal

validateFn receives post-transform data { rates: [...] }, not the raw
{ policy, exchange, credit } shape. The old check always returned falsy,
causing atomicPublish to skip every write.

Also restores process.exit(1) on fatal error so Railway alerts on seed
failures instead of silently exiting clean.
This commit is contained in:
Elie Habib
2026-03-26 05:24:51 +04:00
parent 002be8ea8b
commit 4714d6b1d1

View File

@@ -200,8 +200,9 @@ async function fetchAll() {
return { policy, exchange, credit };
}
// validateFn receives the post-transform data ({ rates: [...] }), not the raw fetchAll shape.
function validate(data) {
return data?.policy || data?.exchange || data?.credit;
return Array.isArray(data?.rates) && data.rates.length > 0;
}
// publishTransform: store only policy data (correct shape) at canonical key.
@@ -225,6 +226,6 @@ if (process.argv[1]?.endsWith('seed-bis-data.mjs')) {
}).catch((err) => {
const _cause = err.cause ? ` (cause: ${err.cause.message || err.cause.code || err.cause})` : '';
console.error('FATAL:', (err.message || err) + _cause);
process.exit(0);
process.exit(1);
});
}