mirror of
https://github.com/khairul169/vaulterm.git
synced 2025-04-28 16:49:39 +07:00
26 lines
456 B
Go
26 lines
456 B
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func ErrorHandler(ctx *fiber.Ctx, err error) error {
|
|
// Status code defaults to 500
|
|
code := fiber.StatusInternalServerError
|
|
|
|
// Retrieve the custom status code if it's a *fiber.Error
|
|
var e *fiber.Error
|
|
if errors.As(err, &e) {
|
|
code = e.Code
|
|
}
|
|
|
|
// Return from handler
|
|
return ctx.Status(code).JSON(fiber.Map{
|
|
"status": "error",
|
|
"code": code,
|
|
"message": err.Error(),
|
|
})
|
|
}
|