customer/internal/utils/client_response.go

25 lines
591 B
Go
Raw Normal View History

2023-05-16 01:12:07 +00:00
package utils
import (
"net/http"
2023-05-16 04:01:55 +00:00
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
2023-05-16 01:12:07 +00:00
)
var clientErrors = map[int]error{
2023-05-17 20:27:09 +00:00
http.StatusInternalServerError: errors.ErrInternalError,
2023-05-16 01:12:07 +00:00
http.StatusBadRequest: errors.ErrInvalidArgs,
http.StatusNotImplemented: errors.ErrMethodNotImplemented,
2023-05-17 20:27:09 +00:00
http.StatusNotFound: errors.ErrNotFound,
http.StatusForbidden: errors.ErrNoAccess,
2023-05-16 01:12:07 +00:00
}
func DetermineClientErrorResponse(statusCode int) error {
err, ok := clientErrors[statusCode]
if !ok {
2023-05-17 20:27:09 +00:00
return errors.ErrInternalError
2023-05-16 01:12:07 +00:00
}
return err
}