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
🐛 Sub fiber's error handlers not working #1839
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
package main
import (
"fmt"
"log"
"github.com/gofiber/fiber/v2"
)
// Custom error handler.
func apiErrorHandler(c *fiber.Ctx, err error) error {
// Custom error handling logic here.
// ...
fmt.Println("apiErrorHandler", err)
// Return from handler
return fiber.DefaultErrorHandler(c, err)
}
func main() {
app := fiber.New()
// Steps to reproduce
api := fiber.New(fiber.Config{
ErrorHandler: apiErrorHandler,
})
api.Get("/test", func(ctx *fiber.Ctx) error {
return fiber.ErrBadRequest
})
app.Mount("/api", api)
log.Fatal(app.Listen(":3000"))
} curl -i http://localhost:3000/api/test can not reproduce, need more information on this for me it works as seen in the screenshot can you( @h4ckedneko ) refine your example or describe the error in more detail ? |
Hello, I created a git repo to reproduce this bug: |
Both v2.25.0 and v2.31.0 have the same fiber setup. But if you run them, the recent version doesn't print "custom error handler called" meaning the custom error handler is not being registered. |
okay found the error, it only occurs when you root mounted apps from other fiber instances we will fix it, thanks for the info related to the refactoring from : |
Thanks Fiber team! 🥳 |
Fiber version
v2.30.0
Issue description
In v2.24.0, custom error handler in fiber sub apps is captured by the main fiber app when you mounted them (#1560). But this doesn't work anymore with the recent version.
Code snippet
The text was updated successfully, but these errors were encountered: