2021-08-09 08:53:58 +00:00
|
|
|
package errors
|
2020-07-22 13:02:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// ErrorCode type of error status.
|
|
|
|
ErrorCode int
|
|
|
|
|
2021-08-09 08:53:58 +00:00
|
|
|
// Error structure represents API error.
|
|
|
|
Error struct {
|
|
|
|
ErrCode ErrorCode
|
|
|
|
Code string
|
|
|
|
Description string
|
|
|
|
HTTPStatusCode int
|
|
|
|
}
|
2020-07-22 13:02:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const maxEConfigJSONSize = 262272
|
|
|
|
|
2021-07-12 13:18:52 +00:00
|
|
|
// IsS3Error check if the provided error is a specific s3 error.
|
|
|
|
func IsS3Error(err error, code ErrorCode) bool {
|
|
|
|
e, ok := err.(Error)
|
|
|
|
return ok && e.ErrCode == code
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:34:06 +00:00
|
|
|
func (e Error) Error() string {
|
|
|
|
return fmt.Sprintf("%s: %d => %s", e.Code, e.HTTPStatusCode, e.Description)
|
|
|
|
}
|
|
|
|
|
2021-08-19 06:55:22 +00:00
|
|
|
// ObjectError - error that linked to specific object.
|
|
|
|
type ObjectError struct {
|
|
|
|
Err error
|
|
|
|
Object string
|
|
|
|
Version string
|
2020-08-06 12:02:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 06:55:22 +00:00
|
|
|
func (e ObjectError) Error() string {
|
|
|
|
return fmt.Sprintf("%s (%s:%s)", e.Err, e.Object, e.Version)
|
2020-08-22 02:36:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 06:55:22 +00:00
|
|
|
// ObjectVersion get "object:version" string.
|
|
|
|
func (e ObjectError) ObjectVersion() string {
|
|
|
|
return e.Object + ":" + e.Version
|
2020-08-22 02:36:53 +00:00
|
|
|
}
|