Skip to content

feat(error-handler): include requestId in every error response#1136

Open
semantabhandari wants to merge 1 commit into
mainfrom
feat/error-handler-request-id-in-response
Open

feat(error-handler): include requestId in every error response#1136
semantabhandari wants to merge 1 commit into
mainfrom
feat/error-handler-request-id-in-response

Conversation

@semantabhandari

Copy link
Copy Markdown
Contributor

Every error response now carries requestId (fastify's request.id) alongside the existing fields. When the app configures requestIdHeader (e.g. a load balancer's x-request-id), that same id is echoed back, so a client-reported failure can be correlated directly with its request-scoped log entries instead of searching by message and timestamp.

Additive change: new field on the ErrorResponse type, the registered ErrorResponse JSON schema, and all three handler branches (HttpError, domain-mapped, unhandled 500). No behavioural change to status codes or logging. New requestId.test.ts covers all three lanes plus header-supplied ids; README/FEATURES updated. 55/55 tests, typecheck and lint clean.

Add fastify's request.id to the ErrorResponse envelope in all three
branches (HttpError, domain-mapped, unhandled fallback) and to the
registered ErrorResponse JSON schema. A client-reported failure can now
be correlated with its request-scoped log entries by quoting the id
from the response body; when requestIdHeader is configured the id the
load balancer supplied is echoed back.
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.

1 participant