Skip to content

fix(fetchZyfiSponsored): enhance error handling and logging - #118

Merged
Douglasacost merged 3 commits into
mainfrom
clk-gateway/error-logs
Jul 8, 2026
Merged

fix(fetchZyfiSponsored): enhance error handling and logging#118
Douglasacost merged 3 commits into
mainfrom
clk-gateway/error-logs

Conversation

@Douglasacost

@DouglasacostDouglasacost commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Centralizes ZyFi paymaster logging in fetchZyfiSponsored so every call site shares the same format.

Log levelFormatWhen
logZyFi request [operation]: …Before each ZyFi API call
logZyFi response [operation]: …On success
errorZyFi error [operation] {status} {statusText}: …On HTTP error (includes response body)

Call sites pass an operation label (register, set-text-record) instead of duplicating log statements. The legacy register route in index.ts is included for consistency.

Errors throw with the operation name and API message (or serialized body) for easier tracing in request logs.

Test plan

  • Trigger a ZyFi-sponsored register — confirm request/response logs appear with [register]
  • Trigger a ZyFi-sponsored set-text-record — confirm logs appear with [set-text-record]
  • Simulate a ZyFi API failure — confirm error log includes HTTP status and response body

Updated the fetchZyfiSponsored function to improve error handling by logging the response status and body when a fetch fails. This change provides clearer insights into the failure reasons. Additionally, adjusted the response parsing to use a single await for the response body, ensuring consistency in handling the response data.
@github-actions

github-actionsBot commented Jun 3, 2026

Copy link
Copy Markdown

LCOV of commit 6535249 during checks #746

Summary coverage rate:
lines......: 27.1% (939 of 3463 lines)
functions..: 27.5% (150 of 546 functions)
branches...: 28.1% (164 of 583 branches)
Files changed coverage rate: n/a

aliXsedand others added 2 commits July 9, 2026 10:50
Move operation-tagged logging into fetchZyfiSponsored so all call sites
(register, set-text-record, legacy index route) share the same format and
error output includes HTTP status plus response body.
Co-authored-by: Cursor <cursoragent@cursor.com>
@Douglasacost
Douglasacost merged commit e1bb0a2 into mainJul 8, 2026
3 checks passed
@Douglasacost
Douglasacost deleted the clk-gateway/error-logs branch July 8, 2026 23:03
Douglasacost added a commit that referenced this pull request Jul 30, 2026
Builds on #118, which added ZyFi status and body logging. Three gaps remain.
1. The global Express error middleware returns a 500 to the client but never
logs, so no unexpected error on any route leaves a server-side trace. Log
the message and stack for 500s, and log handled HttpErrors at warn level
with method and URL.
2. `fetchZyfiSponsored` did not distinguish a network-level failure (DNS, TLS,
connection reset) from an HTTP rejection. The request never reaches ZyFi in
that case, so there is no status or body to report; say so explicitly.
3. `await response.json()` ran before the `response.ok` check, so a non-JSON
error body — an HTML or empty response from a proxy or load balancer in
front of ZyFi — threw a SyntaxError that discarded the status and left the
same blind spot #118 set out to close. Read the body as text first, then
parse, so the status survives a non-JSON response.
Keeps the `operation` label convention introduced in #118.
aliXsed pushed a commit that referenced this pull request Aug 5, 2026
…hs (#125)
Builds on #118, which added ZyFi status and body logging. Three gaps remain.
1. The global Express error middleware returns a 500 to the client but never
logs, so no unexpected error on any route leaves a server-side trace. Log
the message and stack for 500s, and log handled HttpErrors at warn level
with method and URL.
2. `fetchZyfiSponsored` did not distinguish a network-level failure (DNS, TLS,
connection reset) from an HTTP rejection. The request never reaches ZyFi in
that case, so there is no status or body to report; say so explicitly.
3. `await response.json()` ran before the `response.ok` check, so a non-JSON
error body — an HTML or empty response from a proxy or load balancer in
front of ZyFi — threw a SyntaxError that discarded the status and left the
same blind spot #118 set out to close. Read the body as text first, then
parse, so the status survives a non-JSON response.
Keeps the `operation` label convention introduced in #118.
Sign up for freeto 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.

2 participants

@Douglasacost@aliXsed