106 lines
1.8 KiB
Go
106 lines
1.8 KiB
Go
package utils
|
|
|
|
import "fmt"
|
|
|
|
func StatusCodesToError(statusCode int) error {
|
|
var err error
|
|
switch statusCode {
|
|
case 403:
|
|
err = AccessDeniedError{}
|
|
case 404:
|
|
err = NotFoundError{}
|
|
case 412:
|
|
err = PreconditionFailedError{}
|
|
case 421:
|
|
err = RateLimitReachedError{}
|
|
case 424:
|
|
err = InvalidParametersError{}
|
|
case 500:
|
|
err = InternalServerError{}
|
|
case 502:
|
|
err = BadGatewayError{}
|
|
case 503:
|
|
err = ServiceUnavailableError{}
|
|
default:
|
|
err = fmt.Errorf("unhandels status code: %d", statusCode)
|
|
}
|
|
return err
|
|
}
|
|
|
|
type AccessDeniedError struct {
|
|
}
|
|
|
|
func (_ AccessDeniedError) Error() string {
|
|
return "access denied"
|
|
}
|
|
|
|
type NotFoundError struct {
|
|
}
|
|
|
|
func (_ NotFoundError) Error() string {
|
|
return "not found"
|
|
}
|
|
|
|
type PreconditionFailedError struct {
|
|
}
|
|
|
|
func (_ PreconditionFailedError) Error() string {
|
|
return "precondition failed"
|
|
}
|
|
|
|
type RateLimitReachedError struct {
|
|
}
|
|
|
|
func (_ RateLimitReachedError) Error() string {
|
|
return "rate limit reached"
|
|
}
|
|
|
|
type InvalidParametersError struct {
|
|
}
|
|
|
|
func (_ InvalidParametersError) Error() string {
|
|
return "invalide parameters"
|
|
}
|
|
|
|
type InternalServerError struct {
|
|
}
|
|
|
|
func (_ InternalServerError) Error() string {
|
|
return "internal server error"
|
|
}
|
|
|
|
type BadGatewayError struct {
|
|
}
|
|
|
|
func (_ BadGatewayError) Error() string {
|
|
return "bad gateway"
|
|
}
|
|
|
|
type ServiceUnavailableError struct {
|
|
}
|
|
|
|
func (_ ServiceUnavailableError) Error() string {
|
|
return "service unavailable"
|
|
}
|
|
|
|
type UnknownError struct {
|
|
}
|
|
|
|
func (_ UnknownError) Error() string {
|
|
return "unknown error"
|
|
}
|
|
|
|
type OriginConnectionTimeOutError struct {
|
|
}
|
|
|
|
func (_ OriginConnectionTimeOutError) Error() string {
|
|
return "origin connection time-out"
|
|
}
|
|
|
|
type SSLHandshakeFailedError struct {
|
|
}
|
|
|
|
func (_ SSLHandshakeFailedError) Error() string {
|
|
return "ssl handshake failed"
|
|
}
|