customer/internal/utils/client_response.go

25 lines
591 B
Go
Raw Normal View History

2023-06-22 09:36:43 +00:00
package utils
import (
"net/http"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
)
var clientErrors = map[int]error{
http.StatusInternalServerError: errors.ErrInternalError,
http.StatusBadRequest: errors.ErrInvalidArgs,
http.StatusNotImplemented: errors.ErrMethodNotImplemented,
http.StatusNotFound: errors.ErrNotFound,
http.StatusForbidden: errors.ErrNoAccess,
}
func DetermineClientErrorResponse(statusCode int) error {
err, ok := clientErrors[statusCode]
if !ok {
return errors.ErrInternalError
}
return err
}