Skip to content

fix: preserve bad request status codes - #8

Merged
PANiXiDA merged 4 commits into
mainfrom
feature/handle-bad-http-requests
Aug 2, 2026
Merged

fix: preserve bad request status codes#8
PANiXiDA merged 4 commits into
mainfrom
feature/handle-bad-http-requests

Conversation

@PANiXiDA

@PANiXiDA PANiXiDA commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Added a dedicated BadHttpRequestException handler before the catch-all exception handler.
  • Preserved the framework-provided client status code and returned application/problem+json.
  • Logged invalid HTTP requests at warning level and hid parser details outside Development.
  • Centralized shared HTTP request log attributes in Logging/HttpRequestLogScope for middleware and exception handlers.
  • Centralized exception ProblemDetails creation, Development detail policy, and trace extensions in Errors/ExceptionProblemDetailsFactory.
  • Added unit and real pipeline regression tests and documented the behavior.

Why

Minimal API JSON body binding failures throw BadHttpRequestException in 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 Release

Send 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

  • Contract: malformed or unbindable requests now return the status carried by BadHttpRequestException, normally HTTP 400, instead of HTTP 500.
  • No public API, configuration, migration, or package dependency changes.
  • Valid requests and application validation behavior are unchanged.

@PANiXiDA
PANiXiDA marked this pull request as ready for review August 2, 2026 18:32
@PANiXiDA
PANiXiDA merged commit e5881c3 into main Aug 2, 2026
6 checks passed
@PANiXiDA
PANiXiDA deleted the feature/handle-bad-http-requests branch August 2, 2026 18:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

2 participants