Skip to content

Conversation

@enicioli
Copy link
Contributor

@enicioli enicioli commented Oct 27, 2025

Description

This pull request enhances the way HTTP status codes are reported in metrics when exceptions occur in the MetricMiddleware. Instead of always reporting a 500 status code for exceptions, the middleware now checks if the exception code corresponds to a valid HTTP status and uses it when appropriate. The test suite is updated to verify this new behavior with multiple exception codes.

Context

This change is particularly impactful in contexts where the application employs custom exception handlers to intercept exceptions and explicitly set the HTTP status code of the response.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Performance/Refactor
  • CI/CD/Chore

Checklist

  • Title follows Conventional Commits (e.g., feat: add SQS aspect)
  • Tests added/updated
  • composer test passes locally
  • Documentation updated (README/Docs)
  • No breaking changes (or documented if any)

@enicioli enicioli force-pushed the http-exception-code branch 2 times, most recently from 1ca418d to 9b81742 Compare October 27, 2025 13:24
@enicioli enicioli marked this pull request as ready for review October 27, 2025 13:42
Copilot AI review requested due to automatic review settings October 27, 2025 13:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where HTTP exceptions were always reported with a 500 status code in metrics, regardless of their actual status code. Now the middleware intelligently checks if an exception's code represents a valid HTTP status and uses it when appropriate, falling back to 500 for invalid codes.

Key changes:

  • Modified MetricMiddleware to extract and validate HTTP status codes from exceptions
  • Added helper methods to determine if an exception code is a valid HTTP status
  • Enhanced test coverage with a data provider testing multiple exception code scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Middleware/MetricMiddleware.php Added logic to extract valid HTTP status codes from exceptions and introduced helper methods for validation
tests/Unit/Middleware/MetricMiddlewareTest.php Converted exception test to use data provider covering default, valid HTTP, and custom exception codes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@opencodeco opencodeco deleted a comment from Copilot AI Oct 27, 2025
@opencodeco opencodeco deleted a comment from Copilot AI Oct 27, 2025
@enicioli enicioli force-pushed the http-exception-code branch from 9b81742 to a1586eb Compare October 27, 2025 14:45
@enicioli enicioli merged commit 395826c into main Oct 27, 2025
@enicioli enicioli deleted the http-exception-code branch October 27, 2025 18:23
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