fix: expose Fastify request id in error envelope for incident correlation - #166
Merged
dev-fani merged 1 commit intoAug 30, 2026
Merged
Conversation
…tion Add the request id to every error response body so a user reporting a 5xx can share it and support can correlate to the matching request log line. Also mask 5xx AppError details from client responses (previously echoed despite the tests asserting otherwise) to avoid leaking internal DB/RPC details, and repair the spec's AppError fixtures whose constructor signatures set no code/statusCode. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@Sundayabel222 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #77
Closes #86
Closes #87
Closes #88
Summary
When a user reports "I got a 500", support currently has nothing to correlate it against. Fastify already generates a request id and embeds it (
req.id) in every request log line, but the HTTP error envelope never exposed it.This PR surfaces that id in every error response shape —
{ error: { code, message, ... }, requestId }— so a reported error can be matched directly to its request log entry:{ "error": { "code": "INTERNAL_ERROR", "message": "An unexpected error occurred" }, "requestId": "req-2" }Changes
src/shared/errors/error-handler.tsrequestIdtoErrorResponseBody, populated fromrequest.idin all error branches (AppError, ZodError, Fastify-validation, each of the 5 Prisma codes, Fastify 4xx, and the masked 500).error.detailsto clients even on 5xxAppErrors (e.g. DB connection strings, RPC payloads). Details on ≥500 responses are now logged server-side but omitted from the client payload. This aligns the handler with what the spec already asserted, and is a security-sensible default.src/shared/errors/error-handler.spec.tsid: 'req-123'; added assertions thatrequestIdflows through on 5xx, 4xx, and generic-500 paths.AppErrorsubclasses calledsuper('CODE', message, status, details)— a 4-arg call into a 2-arg constructor — leavingcode/statusCodeundefinedand silently making 5 of the 8 tests fail. They now define realcode/statusCodefields. (Pre-existing failure, unrelated to the feature; you can reproduce onmain.)Verification
pnpm vitest run src/shared/errors/error-handler.spec.ts→ 8/8 passingpnpm exec eslinton both changed files → cleantypecheckerrors introduced in the touched files (the repo has unrelated, pre-existing errors in notifications routes,env.test.ts,redact.spec.ts, and the e2e specs that I left untouched).Notes
requestIdis the same value Fastify logs asreq.idin the request log line, so it's a direct correlation key.error.detailsbeing returned (verified across integration/spec tests).Closes the incident-correlation gap reported in the issue.