api: Extend S3 errors with Minio errors. (#1533)

Fixes #1530
master
Harshavardhana 9 years ago committed by Anand Babu (AB) Periasamy
parent 75320f70d0
commit 76c511c9fe
  1. 52
      api-errors.go
  2. 10
      object-errors.go
  3. 4
      web-handlers.go

@ -83,8 +83,6 @@ const (
ErrMalformedPOSTRequest ErrMalformedPOSTRequest
ErrSignatureVersionNotSupported ErrSignatureVersionNotSupported
ErrBucketNotEmpty ErrBucketNotEmpty
ErrStorageFull
ErrObjectExistsAsPrefix
ErrAllAccessDisabled ErrAllAccessDisabled
ErrMalformedPolicy ErrMalformedPolicy
ErrMissingFields ErrMissingFields
@ -99,7 +97,6 @@ const (
ErrMalformedDate ErrMalformedDate
ErrMalformedExpires ErrMalformedExpires
ErrAuthHeaderEmpty ErrAuthHeaderEmpty
ErrDateHeaderMissing
ErrExpiredPresignRequest ErrExpiredPresignRequest
ErrMissingDateHeader ErrMissingDateHeader
ErrInvalidQuerySignatureAlgo ErrInvalidQuerySignatureAlgo
@ -107,9 +104,11 @@ const (
ErrBucketAlreadyOwnedByYou ErrBucketAlreadyOwnedByYou
// Add new error codes here. // Add new error codes here.
// Extended errors. // Minio extended errors.
ErrReadQuorum ErrReadQuorum
ErrWriteQuorum ErrWriteQuorum
ErrStorageFull
ErrObjectExistsAsDirectory
) )
// error code to APIError structure, these fields carry respective // 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.", Description: "We encountered an internal error, please try again.",
HTTPStatusCode: http.StatusInternalServerError, 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: { ErrInvalidAccessKeyID: {
Code: "InvalidAccessKeyID", Code: "InvalidAccessKeyID",
Description: "The access key ID you provided does not exist in our records.", 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.", Description: "The bucket you tried to delete is not empty.",
HTTPStatusCode: http.StatusConflict, 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: { ErrAllAccessDisabled: {
Code: "AllAccessDisabled", Code: "AllAccessDisabled",
Description: "All access to this bucket has been disabled.", 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.", Description: "Your previous request to create the named bucket succeeded and you already own it.",
HTTPStatusCode: http.StatusConflict, 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. // Add your error structure here.
} }
@ -436,8 +436,8 @@ func toAPIErrorCode(err error) (apiErr APIErrorCode) {
apiErr = ErrBadDigest apiErr = ErrBadDigest
case IncompleteBody: case IncompleteBody:
apiErr = ErrIncompleteBody apiErr = ErrIncompleteBody
case ObjectExistsAsPrefix: case ObjectExistsAsDirectory:
apiErr = ErrObjectExistsAsPrefix apiErr = ErrObjectExistsAsDirectory
case BucketNameInvalid: case BucketNameInvalid:
apiErr = ErrInvalidBucketName apiErr = ErrInvalidBucketName
case BucketNotFound: case BucketNotFound:

@ -46,7 +46,7 @@ func toObjectErr(err error, params ...string) error {
return InsufficientWriteQuorum{} return InsufficientWriteQuorum{}
case errIsNotRegular, errFileAccessDenied: case errIsNotRegular, errFileAccessDenied:
if len(params) >= 2 { if len(params) >= 2 {
return ObjectExistsAsPrefix{ return ObjectExistsAsDirectory{
Bucket: params[0], Bucket: params[0],
Object: params[1], Object: params[1],
} }
@ -112,11 +112,11 @@ func (e ObjectNotFound) Error() string {
return "Object not found: " + e.Bucket + "#" + e.Object return "Object not found: " + e.Bucket + "#" + e.Object
} }
// ObjectExistsAsPrefix object already exists with a requested prefix. // ObjectExistsAsDirectory object already exists as a directory.
type ObjectExistsAsPrefix GenericError type ObjectExistsAsDirectory GenericError
func (e ObjectExistsAsPrefix) Error() string { func (e ObjectExistsAsDirectory) Error() string {
return "Object exists on : " + e.Bucket + " as prefix " + e.Object return "Object exists on : " + e.Bucket + " as directory " + e.Object
} }
// BucketExists bucket exists. // BucketExists bucket exists.

@ -405,8 +405,8 @@ func writeWebErrorResponse(w http.ResponseWriter, err error) {
apiErrCode = ErrBadDigest apiErrCode = ErrBadDigest
case IncompleteBody: case IncompleteBody:
apiErrCode = ErrIncompleteBody apiErrCode = ErrIncompleteBody
case ObjectExistsAsPrefix: case ObjectExistsAsDirectory:
apiErrCode = ErrObjectExistsAsPrefix apiErrCode = ErrObjectExistsAsDirectory
case ObjectNotFound: case ObjectNotFound:
apiErrCode = ErrNoSuchKey apiErrCode = ErrNoSuchKey
case ObjectNameInvalid: case ObjectNameInvalid:

Loading…
Cancel
Save