package utils import ( "net/http" "github.com/labstack/echo/v4" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models" ) var httpStatuses = map[errors.ErrorType]int{ errors.ErrInternalError: http.StatusInternalServerError, errors.ErrInvalidArgs: http.StatusBadRequest, errors.ErrNoAccess: http.StatusForbidden, errors.ErrNotFound: http.StatusNotFound, errors.ErrMethodNotImplemented: http.StatusNotImplemented, errors.ErrConflict: http.StatusConflict, } func DetermineEchoErrorResponse(ctx echo.Context, err errors.Error) error { status, ok := httpStatuses[err.Type()] if !ok { return ctx.JSON(http.StatusInternalServerError, models.ResponseErrorHTTP{ StatusCode: http.StatusInternalServerError, Message: err.Error(), }) } return ctx.JSON(status, models.ResponseErrorHTTP{ StatusCode: status, Message: err.Error(), }) }