From 76c511c9fefa1983e9fc57eeab0cc0fd16c3e2ef Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 8 May 2016 12:36:16 -0700 Subject: [PATCH] api: Extend S3 errors with Minio errors. (#1533) Fixes #1530 --- api-errors.go | 52 ++++++++++++++++++++++++------------------------ object-errors.go | 10 +++++----- web-handlers.go | 4 ++-- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/api-errors.go b/api-errors.go index a629b2ebd..4fd2ef3c9 100644 --- a/api-errors.go +++ b/api-errors.go @@ -83,8 +83,6 @@ const ( ErrMalformedPOSTRequest ErrSignatureVersionNotSupported ErrBucketNotEmpty - ErrStorageFull - ErrObjectExistsAsPrefix ErrAllAccessDisabled ErrMalformedPolicy ErrMissingFields @@ -99,7 +97,6 @@ const ( ErrMalformedDate ErrMalformedExpires ErrAuthHeaderEmpty - ErrDateHeaderMissing ErrExpiredPresignRequest ErrMissingDateHeader ErrInvalidQuerySignatureAlgo @@ -107,9 +104,11 @@ const ( ErrBucketAlreadyOwnedByYou // Add new error codes here. - // Extended errors. + // Minio extended errors. ErrReadQuorum ErrWriteQuorum + ErrStorageFull + ErrObjectExistsAsDirectory ) // error code to APIError structure, these fields carry respective @@ -190,16 +189,6 @@ var errorCodeResponse = map[APIErrorCode]APIError{ Description: "We encountered an internal error, please try again.", HTTPStatusCode: http.StatusInternalServerError, }, - ErrReadQuorum: { - Code: "ReadQuorum", - Description: "Multiple disk failures, unable to reconstruct data.", - HTTPStatusCode: http.StatusServiceUnavailable, - }, - ErrWriteQuorum: { - Code: "WriteQuorum", - Description: "Multiple disks failures, unable to write data.", - HTTPStatusCode: http.StatusServiceUnavailable, - }, ErrInvalidAccessKeyID: { Code: "InvalidAccessKeyID", Description: "The access key ID you provided does not exist in our records.", @@ -310,16 +299,6 @@ var errorCodeResponse = map[APIErrorCode]APIError{ Description: "The bucket you tried to delete is not empty.", HTTPStatusCode: http.StatusConflict, }, - ErrStorageFull: { - Code: "StorageFull", - Description: "Storage backend has reached its minimum free disk threshold. Please delete few objects to proceed.", - HTTPStatusCode: http.StatusInternalServerError, - }, - ErrObjectExistsAsPrefix: { - Code: "ObjectExistsAsPrefix", - Description: "An object already exists as your prefix, choose a different prefix to proceed.", - HTTPStatusCode: http.StatusConflict, - }, ErrAllAccessDisabled: { Code: "AllAccessDisabled", Description: "All access to this bucket has been disabled.", @@ -415,6 +394,27 @@ var errorCodeResponse = map[APIErrorCode]APIError{ Description: "Your previous request to create the named bucket succeeded and you already own it.", HTTPStatusCode: http.StatusConflict, }, + /// Minio extensions. + ErrStorageFull: { + Code: "XMinioStorageFull", + Description: "Storage backend has reached its minimum free disk threshold. Please delete few objects to proceed.", + HTTPStatusCode: http.StatusInternalServerError, + }, + ErrObjectExistsAsDirectory: { + Code: "XMinioObjectExistsAsDirectory", + Description: "Object name already exists as a directory.", + HTTPStatusCode: http.StatusConflict, + }, + ErrReadQuorum: { + Code: "XMinioReadQuorum", + Description: "Multiple disk failures, unable to reconstruct data.", + HTTPStatusCode: http.StatusServiceUnavailable, + }, + ErrWriteQuorum: { + Code: "XMinioWriteQuorum", + Description: "Multiple disks failures, unable to write data.", + HTTPStatusCode: http.StatusServiceUnavailable, + }, // Add your error structure here. } @@ -436,8 +436,8 @@ func toAPIErrorCode(err error) (apiErr APIErrorCode) { apiErr = ErrBadDigest case IncompleteBody: apiErr = ErrIncompleteBody - case ObjectExistsAsPrefix: - apiErr = ErrObjectExistsAsPrefix + case ObjectExistsAsDirectory: + apiErr = ErrObjectExistsAsDirectory case BucketNameInvalid: apiErr = ErrInvalidBucketName case BucketNotFound: diff --git a/object-errors.go b/object-errors.go index 766b0b753..812ce219f 100644 --- a/object-errors.go +++ b/object-errors.go @@ -46,7 +46,7 @@ func toObjectErr(err error, params ...string) error { return InsufficientWriteQuorum{} case errIsNotRegular, errFileAccessDenied: if len(params) >= 2 { - return ObjectExistsAsPrefix{ + return ObjectExistsAsDirectory{ Bucket: params[0], Object: params[1], } @@ -112,11 +112,11 @@ func (e ObjectNotFound) Error() string { return "Object not found: " + e.Bucket + "#" + e.Object } -// ObjectExistsAsPrefix object already exists with a requested prefix. -type ObjectExistsAsPrefix GenericError +// ObjectExistsAsDirectory object already exists as a directory. +type ObjectExistsAsDirectory GenericError -func (e ObjectExistsAsPrefix) Error() string { - return "Object exists on : " + e.Bucket + " as prefix " + e.Object +func (e ObjectExistsAsDirectory) Error() string { + return "Object exists on : " + e.Bucket + " as directory " + e.Object } // BucketExists bucket exists. diff --git a/web-handlers.go b/web-handlers.go index c599fedca..909eeecc7 100644 --- a/web-handlers.go +++ b/web-handlers.go @@ -405,8 +405,8 @@ func writeWebErrorResponse(w http.ResponseWriter, err error) { apiErrCode = ErrBadDigest case IncompleteBody: apiErrCode = ErrIncompleteBody - case ObjectExistsAsPrefix: - apiErrCode = ErrObjectExistsAsPrefix + case ObjectExistsAsDirectory: + apiErrCode = ErrObjectExistsAsDirectory case ObjectNotFound: apiErrCode = ErrNoSuchKey case ObjectNameInvalid: