25 lines
433 B
Go
25 lines
433 B
Go
package exception
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"epic-ent/internal/domain/vo"
|
|
)
|
|
|
|
func RegisterErrorHandler(e *echo.Echo) {
|
|
e.HTTPErrorHandler = func(err error, c echo.Context) {
|
|
code := http.StatusInternalServerError
|
|
msg := err.Error()
|
|
if he, ok := err.(*echo.HTTPError); ok {
|
|
code = he.Code
|
|
if he.Message != nil {
|
|
msg = he.Message.(string)
|
|
}
|
|
}
|
|
|
|
_ = c.JSON(code, vo.Error(msg))
|
|
}
|
|
}
|