Skip to content

chore(logging): add console logging when zyte API call fails - #383

Closed
jpetto wants to merge 1 commit into
mainfrom
HNT-2442-log-zyte-api-failures
Closed

chore(logging): add console logging when zyte API call fails#383
jpetto wants to merge 1 commit into
mainfrom
HNT-2442-log-zyte-api-failures

Conversation

@jpetto

@jpetto jpetto commented Apr 15, 2026

Copy link
Copy Markdown
Contributor
  • HNT-2442

Goal

log zyte api errors to the console as a first step to better address parse issues.

References

JIRA ticket:

@jpetto
jpetto requested a review from a team as a code owner April 15, 2026 15:23
@claude

claude Bot commented Apr 15, 2026

Copy link
Copy Markdown

Claude finished @jpetto's task in 57s —— View job


PR Review

  • Read CLAUDE.md for repo guidelines
  • Read changed file and diff
  • Analyze code and provide review feedback

Overall the intent here is solid — distinguishing HTTP-level failures from JSON parse failures gives much better signal for debugging Zyte issues. The changes are clean and the Sentry messages are more informative. One behavioral regression worth addressing before merge:

Critical: fetch() network errors are no longer caught

lib.ts:96 — The outer try/catch was removed, but the fetch() call itself is now unprotected. Any network-level failure (DNS resolution failure, connection refused, timeout, etc.) will throw an uncaught exception that propagates to the caller.

The original code's try/catch covered both the fetch and the JSON parse. The new code only has a try/catch around response.json(). The function's own JSDoc (line 85) still says:

"returns JSON from the metadata service, or an empty object on failure"

That contract is now only partially honored — it holds for HTTP errors and JSON parse errors, but not for network errors.

Suggested fix: wrap the fetch() call in its own try/catch (or wrap the whole block):

let response: Response;

try {
  response = await fetch(metadataParserEnpointUrl, { ... });
} catch (e) {
  Sentry.captureException(
    new Error(`Metadata parser network error for ${url}`),
  );
  console.error('Zyte network error:', { url, error: e });
  return res;
}

Fix this →


Minor: consider logging the error response body on HTTP failures

Right now console.error('Zyte API error:', { url, status, statusText }) is logged for non-OK responses. The Zyte API often returns a JSON body on errors (e.g. { "type": "...", "message": "..." }) that would make debugging much easier. Consider also reading and logging await response.text() (or .json()) on failure — carefully, since it can throw:

let errorBody: string | undefined;
try { errorBody = await response.text(); } catch (_) { /* ignore */ }

console.error('Zyte API error:', {
  url,
  status: response.status,
  statusText: response.statusText,
  body: errorBody,
});

This is a nice-to-have, not a blocker.


Everything else looks good — the separation of HTTP vs. JSON-parse error paths is a clear improvement and the console.error calls give the structured logging that the ticket is asking for.

@jpetto
jpetto force-pushed the HNT-2442-log-zyte-api-failures branch 2 times, most recently from 630518c to 8de8a5d Compare April 15, 2026 17:05
@jpetto
jpetto force-pushed the HNT-2442-log-zyte-api-failures branch from 8de8a5d to 4e0e982 Compare April 15, 2026 18:12
@jpetto

jpetto commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

closed in favor of #404

@jpetto jpetto closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant