This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/e621/utils/error.go

106 lines
1.8 KiB
Go
Raw Normal View History

2023-10-16 13:56:00 +00:00
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"
}