kopia lustrzana https://github.com/reiver/greatape
fix(server): 🚑 unify error format
rodzic
aaff469e47
commit
819ecbc229
|
@ -1,24 +1,12 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func newError(code int, message string) *fiber.Error {
|
||||
data, _ := json.Marshal(struct {
|
||||
Type string `json:"type"`
|
||||
Version int `json:"version"`
|
||||
Payload any `json:"payload"`
|
||||
}{
|
||||
Type: "server_error",
|
||||
Version: 1,
|
||||
Payload: message,
|
||||
})
|
||||
|
||||
return &fiber.Error{
|
||||
Code: code,
|
||||
Message: string(data),
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,15 @@ func New() IServer {
|
|||
}
|
||||
|
||||
ctx.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSONCharsetUTF8)
|
||||
return ctx.Status(code).SendString(err.Error())
|
||||
return ctx.Status(code).JSON(struct {
|
||||
Type string `json:"type"`
|
||||
Version int `json:"version"`
|
||||
Payload any `json:"payload"`
|
||||
}{
|
||||
Type: "server_error",
|
||||
Version: 1,
|
||||
Payload: err.Error(),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue