delphi.market/server/error.go

21 lines
402 B
Go

package server
import (
"net/http"
"strings"
"github.com/labstack/echo/v4"
)
func httpErrorHandler(err error, c echo.Context) {
c.Logger().Error(err)
code := http.StatusInternalServerError
if httpError, ok := err.(*echo.HTTPError); ok {
code = httpError.Code
}
if strings.Contains(err.Error(), "violates check constraint") {
code = 400
}
c.JSON(code, map[string]any{"status": code})
}