Refactoring getAPIErrorResponse method

should receive base error type instead of custom errors

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-08-22 05:36:53 +03:00
parent 0b533e189e
commit d2d54cbdaa

View file

@ -1626,14 +1626,23 @@ func GetAPIError(code ErrorCode) Error {
// getErrorResponse gets in standard error and resource value and
// provides a encodable populated response values
func getAPIErrorResponse(ctx context.Context, err Error, resource, requestID, hostID string) ErrorResponse {
func getAPIErrorResponse(ctx context.Context, err error, resource, requestID, hostID string) ErrorResponse {
code := "BadRequest"
desc := err.Error()
info := GetReqInfo(ctx)
if info == nil {
info = &ReqInfo{}
}
if e, ok := err.(Error); ok {
code = e.Code
desc = e.Description
}
return ErrorResponse{
Code: err.Code,
Message: err.Description,
Code: code,
Message: desc,
BucketName: info.BucketName,
Key: info.ObjectName,
Resource: resource,
@ -2000,3 +2009,13 @@ type PreConditionFailed struct{}
func (e PreConditionFailed) Error() string {
return "At least one of the pre-conditions you specified did not hold"
}
// DeleteError - returns when cant remove object
type DeleteError struct {
Err error
Object string
}
func (e DeleteError) Error() string {
return fmt.Sprintf("%s (%s)", e.Err, e.Object)
}