Skip to content

feature: add structured error logging in makeRequest catch block#128

Closed
mohammedAgility wants to merge 8 commits into
devfrom
feature/add-fetch-error-logging
Closed

feature: add structured error logging in makeRequest catch block#128
mohammedAgility wants to merge 8 commits into
devfrom
feature/add-fetch-error-logging

Conversation

@mohammedAgility
Copy link
Copy Markdown

Problem:
When makeRequest threw an exception, the existing error logging only output the error as a plain string (... ${error}). This made it difficult to diagnose the root cause of fetch failures — particularly in Node.js environments where the underlying network error is nested in error.cause.

Solution
Enhanced the catch block in makeRequest to log a structured error object that captures all relevant diagnostic properties, matching the detail needed to identify underlying network issues.

The following are now logged on every fetch exception:

name | TypeError | Top-level error type
message | fetch failed | Top-level error message
stack | (full trace) | Full stack trace
cause.name | ConnectTimeoutError | Underlying Node.js error type
cause.message | Connect Timeout | Underlying error message
cause.code | UND_ERR_CONNECT_TIMEOUT, ECONNRESET | Machine-readable error code

Changes
src/utils.ts - Added optional details field to the LogProps interface; updated logError to print it when present
src/api-client.ts - Updated catch block in makeRequest to pass structured error details to logError

Notes
Fully backwards compatible - details is optional on LogProps so no other logError call sites are affected
No behaviour change for non-error paths

@joelvarty
Copy link
Copy Markdown
Member

joelvarty commented Mar 10, 2026 via email

@mohammedAgility mohammedAgility changed the base branch from master to dev March 10, 2026 12:59
@AaronAgility
Copy link
Copy Markdown
Contributor

I closed this because it duplicates the efforts of something that was just merged and overwrites that new functionality. If you want to explore increasing the error exposure, please work from a stable main branch.

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.

4 participants