mirror of
https://github.com/hazemKrimi/crimson-vault.git
synced 2026-05-01 18:20:27 +00:00
38 lines
665 B
Go
38 lines
665 B
Go
package api
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/hazemKrimi/crimson-vault/internal/types"
|
|
)
|
|
|
|
func (api *API) CustomErrorHandler(err error, context echo.Context) {
|
|
if context.Response().Committed {
|
|
return
|
|
}
|
|
|
|
custom, ok := err.(types.Error)
|
|
|
|
if ok {
|
|
cause, ok := custom.Cause.(error)
|
|
|
|
if ok {
|
|
api.Logger.Error(cause.Error())
|
|
}
|
|
|
|
context.JSON(custom.Code, map[string][]string{"errors": custom.Messages})
|
|
}
|
|
|
|
herr, ok := err.(*echo.HTTPError)
|
|
|
|
if ok {
|
|
message, ok := herr.Message.(string)
|
|
|
|
if ok {
|
|
context.JSON(herr.Code, map[string][]string{"errors": {message}})
|
|
}
|
|
}
|
|
|
|
api.instance.DefaultHTTPErrorHandler(err, context)
|
|
}
|