fix: preserve bad request status codes - #8
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1e0d0030d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| exception, | ||
| hostEnvironment, | ||
| statusCode, | ||
| ReasonPhrases.GetReasonPhrase(statusCode)); |
There was a problem hiding this comment.
Handle status codes without registered reason phrases
When a BadHttpRequestException carries an unregistered but valid extension status such as 499, ReasonPhrases.GetReasonPhrase returns an empty string, which ExceptionProblemDetailsFactory.Create rejects with ArgumentException. Since this happens inside the exception handler, the original status is not preserved and the request can escape as a 500 instead of receiving Problem Details; use a stable fallback title when no reason phrase exists.
AGENTS.md reference: AGENTS.md:L37-L37
Useful? React with 👍 / 👎.
What changed
BadHttpRequestExceptionhandler before the catch-all exception handler.application/problem+json.Logging/HttpRequestLogScopefor middleware and exception handlers.ProblemDetailscreation, Development detail policy, and trace extensions inErrors/ExceptionProblemDetailsFactory.Why
Minimal API JSON body binding failures throw
BadHttpRequestExceptionin Development. The catch-all handler previously rewrote every such client error to HTTP 500 instead of preserving HTTP 400. Request log attributes and exception Problem Details shaping were also duplicated, which made future infrastructure changes easy to apply inconsistently.How to verify locally
dotnet restore dotnet format dotnet build --configuration Release dotnet test --configuration ReleaseSend malformed JSON for a typed request body, for example an invalid GUID. The response must be HTTP 400 with
application/problem+json; an unexpected application exception must still return HTTP 500.Impact
BadHttpRequestException, normally HTTP 400, instead of HTTP 500.