package web import ( "github.com/gofiber/fiber/v3" "github.com/pkg/errors" ) type ListResponse[E any] struct { Total int64 `json:"total"` List []E `json:"list"` } type Response struct { Code int `json:"code"` Msg string `json:"msg,omitempty"` Data interface{} `json:"data,omitempty"` } func ErrHandle(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 } // Send custom error page err = ctx.Status(code).JSON(Response{ Code: code, Msg: err.Error(), }) if err != nil { // In case the SendFile fails return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } // Return from handler return nil }