mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
The API worker had no error tracking: the Hono onError handler returned a 500 without
logging, and several R2/email failures were swallowed with `.catch(() => {})`, so a
failing Stripe webhook or a data-plane error went unnoticed.
- onError now logs every 5xx as a structured console.error line (captured by Workers
Observability, already enabled in wrangler.jsonc) AND persists it to a new error_logs
D1 table (migration 0013), so incidents survive the short Workers-Logs retention window
and are queryable from our own database:
wrangler d1 execute finance-manager --remote --env prod \
--command "SELECT id, created_at, status, method, path, message FROM error_logs ORDER BY id DESC LIMIT 50"
4xx client errors are intentional control flow and are not recorded (clean signal). The
D1 write is best-effort (executionCtx.waitUntil) and never affects the response.
- Stop swallowing R2 cleanup deletes (account deletion, receipt upload/replace/delete) and
the account-exists notice email; they now console.error.
- New worker test verifies 5xx rows are persisted with method/path/status/message/user_id/
request_id + stack, and that 4xx is not recorded.
No external service or DSN required. Deploy to dev, trigger an error, confirm a row lands in
error_logs before prod.
24 lines
875 B
SQL
24 lines
875 B
SQL
-- Durable production error log for the API worker.
|
|
--
|
|
-- `logWorkerError` (worker/src/errorlog.ts), called from the Hono onError handler, writes 5xx
|
|
-- failures here so incidents survive the short Workers-Logs retention window and stay queryable
|
|
-- from your own database, e.g.:
|
|
-- wrangler d1 execute finance-manager --remote --env prod \
|
|
-- --command "SELECT id, created_at, status, method, path, message FROM error_logs ORDER BY id DESC LIMIT 50"
|
|
--
|
|
-- 4xx client errors are intentional control flow and are NOT recorded here.
|
|
|
|
CREATE TABLE IF NOT EXISTS error_logs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
method TEXT,
|
|
path TEXT,
|
|
status INTEGER,
|
|
message TEXT,
|
|
stack TEXT,
|
|
user_id INTEGER,
|
|
request_id TEXT
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_error_logs_created_at ON error_logs (created_at DESC);
|