Skip to content

feat: add structured error logging for failed API fetches (Closes #949) - #1032

Open
waterWang wants to merge 1 commit into
CredenceOrg:mainfrom
waterWang:feat/log-failed-fetches-949
Open

feat: add structured error logging for failed API fetches (Closes #949)#1032
waterWang wants to merge 1 commit into
CredenceOrg:mainfrom
waterWang:feat/log-failed-fetches-949

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Summary

Add structured calls to the function so every failed API request is captured with the request path, HTTP status, and error message in a machine-readable key=value format.

Changes

  • src/api/client.ts — Import from the existing structured logger and emit:
    • On network failures (status 0): path + error message
    • On non-2xx responses: path + status + error message
  • src/api/client.test.ts — 3 new tests:
    1. Non-2xx response logs path, status, and error
    2. Network error logs status 0 and error message
    3. Successful fetch does not log

Verification

  • ✅ All 53 API tests pass (24 client tests + 29 rate-limit/generated tests)
  • ✅ Structured log output confirmed in test stderr (e.g. event=api_fetch_failed path=/bonds status=404 error=Bond not found)
  • ✅ The existing logger's secret-scrubbing (PII, tokens) is inherited automatically

Closes #949

Add logError calls to the apiFetch function to capture failed requests
with the request path, HTTP status, and error message. This helps
debugging production issues by surfacing structured, machine-readable
log output for every failed API call.

Changes:
- src/api/client.ts: import logError and emit on network failures
  (status 0) and non-2xx responses
- src/api/client.test.ts: 3 new tests covering non-2xx logging,
  network-error logging, and the no-log-on-success path

Closes CredenceOrg#949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging: capture failed fetches with the request-id

1 participant