From 9ac7af00a5b3a7d6e7584f74456759b8c72d217f Mon Sep 17 00:00:00 2001 From: douglasacost Date: Wed, 3 Jun 2026 09:25:13 -0400 Subject: [PATCH] fix(fetchZyfiSponsored): enhance error handling and logging 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. --- clk-gateway/src/helpers.ts | 9 +++++++-- clk-gateway/src/routes/names.ts | 12 ++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clk-gateway/src/helpers.ts b/clk-gateway/src/helpers.ts index 394679f0..0cc5cee0 100644 --- a/clk-gateway/src/helpers.ts +++ b/clk-gateway/src/helpers.ts @@ -205,10 +205,15 @@ export async function fetchZyfiSponsored( body: JSON.stringify(request), }); + const responseBody = await response.json(); if (!response.ok) { - throw new Error(`Failed to fetch zyfi sponsored`); + console.error( + `Failed to fetch zyfi sponsored: ${response.statusText}`, + responseBody, + ); + throw new Error(`Failed to fetch zyfi sponsored: ${responseBody.message}`); } - const sponsoredResponse = (await response.json()) as ZyfiSponsoredResponse; + const sponsoredResponse = responseBody as ZyfiSponsoredResponse; return sponsoredResponse; } diff --git a/clk-gateway/src/routes/names.ts b/clk-gateway/src/routes/names.ts index 55a3030c..9d27d9bc 100644 --- a/clk-gateway/src/routes/names.ts +++ b/clk-gateway/src/routes/names.ts @@ -126,8 +126,11 @@ router.post( let response; if (zyfiSponsoredUrl) { const zyfiRequest = buildZyfiRegisterRequest(owner, name, sub); + console.log(`ZyFi request [register]: ${JSON.stringify(zyfiRequest)}`); const zyfiResponse = await fetchZyfiSponsored(zyfiRequest); - console.log(`ZyFi response: ${JSON.stringify(zyfiResponse)}`); + console.log( + `ZyFi sponsored response [register]: ${JSON.stringify(zyfiResponse)}`, + ); // await admin.auth().revokeRefreshTokens(decodedToken.uid); @@ -268,8 +271,13 @@ router.post( data.key, data.value, ); + console.log( + `ZyFi request [set-text-record]: ${JSON.stringify(zyfiRequest)}`, + ); const zyfiResponse = await fetchZyfiSponsored(zyfiRequest); - console.log(`ZyFi response: ${JSON.stringify(zyfiResponse)}`); + console.log( + `ZyFi sponsored response [set-text-record]: ${JSON.stringify(zyfiResponse)}`, + ); response = await l2Wallet.sendTransaction(zyfiResponse.txData); } else {