mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
Fixed: errors catching in Fiber
This commit is contained in:
parent
3431c4e2fc
commit
6ecd8ea127
@ -16,3 +16,17 @@ func AsApiHandler(f any) any {
|
||||
fx.ResultTags(`group:"api-routes"`),
|
||||
)
|
||||
}
|
||||
|
||||
func errorHandler(c *fiber.Ctx, err error) error {
|
||||
code := fiber.StatusInternalServerError
|
||||
|
||||
// Retrieve the custom status code if it's an fiber.*Error
|
||||
if e, ok := err.(*fiber.Error); ok {
|
||||
code = e.Code
|
||||
}
|
||||
|
||||
// Send json error
|
||||
return c.Status(code).JSON(&fiber.Map{
|
||||
"message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ func New(params Params) (*fiber.App, error) {
|
||||
WriteTimeout: WriteTimeout,
|
||||
IdleTimeout: IdleTimeout,
|
||||
DisableStartupMessage: true,
|
||||
ErrorHandler: errorHandler,
|
||||
})
|
||||
|
||||
app.Use(recover.New())
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
func New() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
if err := c.Next(); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"message": err.Error()})
|
||||
return err
|
||||
}
|
||||
|
||||
contentType := string(c.Response().Header.ContentType())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user