Skip to content

fix: inherit parent RouteNotFound handler for groups with middleware#2986

Open
leno23 wants to merge 1 commit into
labstack:v4from
leno23:fix/group-routenotfound-fallback-2485
Open

fix: inherit parent RouteNotFound handler for groups with middleware#2986
leno23 wants to merge 1 commit into
labstack:v4from
leno23:fix/group-routenotfound-fallback-2485

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 25, 2026

Summary

  • When Group.Use() registers catch-all RouteNotFound routes for middleware execution, inherit the most specific parent RouteNotFound handler from the router tree
  • Fall back to the default NotFoundHandler only when no parent handler exists

Fixes #2485

Problem

Groups created with middleware always registered the default JSON NotFoundHandler for 404 cases, shadowing a custom root RouteNotFound handler.

Test plan

  • go test ./...
  • Added TestGroupRouteNotFoundFallsBackToRootHandler from the issue reproducer
  • Updated TestGroup_RouteNotFoundWithMiddleware expectations for inherited handlers

When a group registers middleware, reuse the most specific parent
RouteNotFound handler instead of always falling back to the default
JSON NotFoundHandler.

Fixes labstack#2485
@leno23 leno23 force-pushed the fix/group-routenotfound-fallback-2485 branch from 3081f5e to 52f5079 Compare May 26, 2026 04:39
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.

1 participant