fix: allow middleware to override error responses with redirects
This change enables middleware to handle errors gracefully by allowing them to return redirect responses even after the error handler has been invoked. Previously, when an error occurred in a downstream handler, the error handler's response would be set and finalized, preventing middleware from providing alternative responses like redirects.
The fix adds an additional condition in the compose function to check if there's an error and the returned response is different from the current context response. This allows middleware to override error responses while maintaining backward compatibility.
Fixes #4530
The author should do the following, if applicable
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 91.52%. Comparing base (342ff3b) to head (0870027).
:warning: Report is 3 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #4546 +/- ##
=======================================
Coverage 91.52% 91.52%
=======================================
Files 172 172
Lines 11221 11223 +2
Branches 3255 3256 +1
=======================================
+ Hits 10270 10272 +2
Misses 950 950
Partials 1 1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.