fix(server): 🚑 unify error format

master
Xeronith 2022-09-08 16:25:28 +04:30
rodzic aaff469e47
commit 819ecbc229
2 zmienionych plików z 10 dodań i 14 usunięć

Wyświetl plik

@ -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,
}
}

Wyświetl plik

@ -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(),
})
},
})