← back to Filemaker Mcp
fix: handle FileMaker 401 no-records gracefully in new-invoice-monitor
cd8f9737bd0d8a650d868f139411161dd9d5d885 · 2026-08-29 04:04:08 -0700 · Steve Abrams
FM error 401 "No records match the request" is the expected response when
there are zero invoices for today (e.g. at 4 AM before orders come in).
Previously this caused process.exit(1), triggering cron-fire-canary WARN.
Now wrapped in try/catch — a 401 logs "0 invoices today" and exits 0.
Real errors (auth failures, network, etc.) still propagate and exit 1.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Files touched
M scripts/new-invoice-monitor.mjs
Diff
commit cd8f9737bd0d8a650d868f139411161dd9d5d885
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Sat Aug 29 04:04:08 2026 -0700
fix: handle FileMaker 401 no-records gracefully in new-invoice-monitor
FM error 401 "No records match the request" is the expected response when
there are zero invoices for today (e.g. at 4 AM before orders come in).
Previously this caused process.exit(1), triggering cron-fire-canary WARN.
Now wrapped in try/catch — a 401 logs "0 invoices today" and exits 0.
Real errors (auth failures, network, etc.) still propagate and exit 1.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---
scripts/new-invoice-monitor.mjs | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/scripts/new-invoice-monitor.mjs b/scripts/new-invoice-monitor.mjs
index bc597ae..ed0896b 100644
--- a/scripts/new-invoice-monitor.mjs
+++ b/scripts/new-invoice-monitor.mjs
@@ -38,11 +38,23 @@ async function post(text) {
async function main() {
const { y, m, d } = ptYMD(new Date());
// Poll today's invoices (sales come in same-day); sort by invoice number ascending.
- const { records } = await findRecords(
- DB, LAYOUT,
- [{ Date: `${m}/${d}/${y}` }],
- { limit: 500, sort: [{ fieldName: 'Invoice', sortOrder: 'ascend' }] },
- );
+ // FileMaker returns error 401 "No records match the request" when there are
+ // zero invoices for today (e.g. at 4 AM before any orders come in). This is
+ // a legitimate empty result — treat it as an empty array and exit 0, not 1.
+ let records;
+ try {
+ ({ records } = await findRecords(
+ DB, LAYOUT,
+ [{ Date: `${m}/${d}/${y}` }],
+ { limit: 500, sort: [{ fieldName: 'Invoice', sortOrder: 'ascend' }] },
+ ));
+ } catch (e) {
+ if (e.fmCode === '401') {
+ console.log('0 invoices today (FileMaker 401 — no records match), nothing to post.');
+ return;
+ }
+ throw e;
+ }
// Numeric invoices only, excluding test records.
const rows = records
← b1dedc0 Guard fix: Schumacher family (DWSW/SCH) is legit-numeric — n
·
back to Filemaker Mcp
·
document invoice monitor launchd recovery proof 84dbe50 →