fix(clk-gateway): log unhandled route errors, harden ZyFi failure paths - #125
Open
Douglasacost wants to merge 1 commit into
Open
fix(clk-gateway): log unhandled route errors, harden ZyFi failure paths#125Douglasacost wants to merge 1 commit into
Douglasacost wants to merge 1 commit into
Conversation
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.
Douglasacost
force-pushed
the
fix/clk-gateway-zyfi-error-logging
branch
from
July 30, 2026 15:00
de38254 to
cf007db
Compare
LCOV of commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased onto
main. Scope narrowed substantially: the original version of this PR duplicated #118, which had already landed. Everything #118 covers has been dropped. What remains is additive only.1. Unhandled route errors are never logged
src/index.ts— the global error middleware returns a 500 to the client but never logs:No unexpected error, on any route, leaves a server-side trace. Now logs message and stack for 500s, and handled
HttpErrors at warn level with method and URL. #118 did not touch this.2. Network-level failures are indistinguishable from HTTP rejections
A DNS, TLS, or connection-reset failure means the request never reached ZyFi, so there is no status or body to report. Previously this surfaced as an unhelpful generic throw. Now reported explicitly as a network failure.
3.
response.json()ran before theokcheckThis is a latent gap in #118:
If a proxy or load balancer in front of ZyFi returns HTML or an empty body — a 502/504 —
response.json()throws aSyntaxErrorand the status is discarded, reproducing exactly the blind spot #118 set out to close. The body is now read as text first and parsed after, so the status survives a non-JSON response.The
operationlabel convention from #118 is preserved throughout.Verification
npx tsc --noEmit— clean.npx jest—routes/names.integration.test.tspasses (7 tests).src/helpers.test.tsfails, but pre-existing and unrelated: verified it fails identically on a clean checkout. Jest does not load.env, soSERVICE_ACCOUNT_KEYis undefined andJSON.parsethrows at import insrc/setup.ts:30. Left untouched.Implementation note: in
helpers.tsthe bare typeResponseresolves to Express'sResponse, not fetch's, henceAwaited<ReturnType<typeof fetch>>.Separately — a deployment lead
#118 removed the
zyfiSponsoredUrl: ${...}log fromhelpers.ts. On currentmainthe only place that string is still logged istestPaymaster.ts, a standalone script. A gateway emitting that line is therefore not running post-#118 code — worth checking whether the deployed build predates 2026-07-08.