Monitoring: /health for uptime checks, structured error logging, API errors without internal details #90

Merged
anas merged 1 commits from feature/monitoring into main 2026-10-09 19:49:08 +00:00
Owner

Closes #82, and the API side of #81. The server side (log rotation, /health through the preview gate, scripts/errors.sh, how to set up an uptime monitor) is in the private repo divan-deploy.

/health (site): asks the API, which asks the database (3 s timeout).

  • 200 {"ok":true,"site":"ok","api":"ok","db":"ok","ms":…} when all three answer;
  • 503 naming the part that is down otherwise;
  • never cached.

An uptime monitor (UptimeRobot, Better Stack…) checks it and alerts the owner.

API

  • GET /api/health checks the database.
  • One error handler: 4xx keep their message. Server errors answer {"error":"سرور میں خرابی۔ تھوڑی دیر بعد کوشش کریں۔"}, never the internal message, and are logged with the method, address and the whole error.

Site: any error while making a page is logged as one JSON line (time, method, path, message, first lines of the stack). The reader sees the Urdu error page from #88.

Tested with test servers:

  • healthy: 200;
  • database unreachable: 503 db: down;
  • API unreachable: 503 api: down;
  • an API request with the database down: 500 with the Urdu message, logged with method, address and message;
  • bad JSON: 400 with its message;
  • a page with the API down: a JSON error line with the path.
  • npm test passes; one test is skipped by design (it needs the data export).

🤖 Generated with Claude Code

Closes #82, and the API side of #81. The server side (log rotation, `/health` through the preview gate, `scripts/errors.sh`, how to set up an uptime monitor) is in the private repo divan-deploy. **`/health`** (site): asks the API, which asks the database (3 s timeout). - `200 {"ok":true,"site":"ok","api":"ok","db":"ok","ms":…}` when all three answer; - `503` naming the part that is down otherwise; - never cached. An uptime monitor (UptimeRobot, Better Stack…) checks it and alerts the owner. **API** - `GET /api/health` checks the database. - One error handler: 4xx keep their message. Server errors answer `{"error":"سرور میں خرابی۔ تھوڑی دیر بعد کوشش کریں۔"}`, never the internal message, and are logged with the method, address and the whole error. **Site:** any error while making a page is logged as one JSON line (time, method, path, message, first lines of the stack). The reader sees the Urdu error page from #88. **Tested** with test servers: - healthy: 200; - database unreachable: 503 `db: down`; - API unreachable: 503 `api: down`; - an API request with the database down: 500 with the Urdu message, logged with method, address and message; - bad JSON: 400 with its message; - a page with the API down: a JSON error line with the path. - `npm test` passes; one test is skipped by design (it needs the data export). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
anas added 1 commit 2026-10-09 17:30:48 +00:00
anas merged commit 415459d55f into main 2026-10-09 19:49:08 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: anas/divan#90
No description provided.