From d2d54cbdaa9b898856c4e9bf1105026a8041e11b Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Sat, 22 Aug 2020 05:36:53 +0300 Subject: [PATCH] Refactoring getAPIErrorResponse method should receive base error type instead of custom errors Signed-off-by: Evgeniy Kulikov --- api/errors.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/api/errors.go b/api/errors.go index 869061418..a0e6e39b7 100644 --- a/api/errors.go +++ b/api/errors.go @@ -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) +}