Skip to content

Conversation

@surajkewat72
Copy link

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

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

surajkewat72 and others added 2 commits November 26, 2025 11:28
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 honojs#4530
@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.52%. Comparing base (342ff3b) to head (0870027).
⚠️ 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           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Redirects not occuring when triggered from middleware

1 participant