Skip to content

feat(middleware): allow passthrough response without enforcing explicit return #1174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kricsleo
Copy link
Member

resolves #1172

This PR enables middleware to pass through the response from other middlewares or handler without enforcing an explicit return next().

This improves DX, especially when the user doesn't care about the response and is likely to forget to return after calling next().

Before:

app.use(async (event, next) => {
  // before...
  const result = await next()
  // after...

  // ↓ this is likely to be forgotton.
  return result
})

After:

app.use(async (event, next) => {
  // before...
  await next()
  // after...

  // no needs to return
})

@kricsleo kricsleo requested a review from pi0 as a code owner July 27, 2025 10:52
Copy link

codecov bot commented Jul 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

v2: Calling await next() in global middleware causes request handlers to be called twice
1 participant