storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/api-errors.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2015, 2016, 2017, 2018 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package cmd
    18  
    19  import (
    20  	"context"
    21  	"encoding/xml"
    22  	"fmt"
    23  	"net/http"
    24  	"net/url"
    25  	"strings"
    26  
    27  	"github.com/Azure/azure-storage-blob-go/azblob"
    28  	minio "github.com/minio/minio-go/v7"
    29  	"github.com/minio/minio-go/v7/pkg/tags"
    30  	"google.golang.org/api/googleapi"
    31  
    32  	"storj.io/minio/cmd/crypto"
    33  	"storj.io/minio/cmd/logger"
    34  	"storj.io/minio/pkg/auth"
    35  	"storj.io/minio/pkg/bucket/lifecycle"
    36  	objectlock "storj.io/minio/pkg/bucket/object/lock"
    37  	"storj.io/minio/pkg/bucket/policy"
    38  	"storj.io/minio/pkg/bucket/replication"
    39  	"storj.io/minio/pkg/bucket/versioning"
    40  	"storj.io/minio/pkg/event"
    41  	"storj.io/minio/pkg/hash"
    42  )
    43  
    44  // APIError structure
    45  type APIError struct {
    46  	Code           string
    47  	Description    string
    48  	HTTPStatusCode int
    49  }
    50  
    51  // APIErrorResponse - error response format
    52  type APIErrorResponse struct {
    53  	XMLName    xml.Name `xml:"Error" json:"-"`
    54  	Code       string
    55  	Message    string
    56  	Key        string `xml:"Key,omitempty" json:"Key,omitempty"`
    57  	BucketName string `xml:"BucketName,omitempty" json:"BucketName,omitempty"`
    58  	Resource   string
    59  	Region     string `xml:"Region,omitempty" json:"Region,omitempty"`
    60  	RequestID  string `xml:"RequestId" json:"RequestId"`
    61  	HostID     string `xml:"HostId" json:"HostId"`
    62  }
    63  
    64  // APIErrorCode type of error status.
    65  type APIErrorCode int
    66  
    67  //go:generate stringer -type=APIErrorCode -trimprefix=Err $GOFILE
    68  
    69  // Error codes, non exhaustive list - http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
    70  const (
    71  	ErrNone APIErrorCode = iota
    72  	ErrAccessDenied
    73  	ErrBadDigest
    74  	ErrEntityTooSmall
    75  	ErrEntityTooLarge
    76  	ErrPolicyTooLarge
    77  	ErrIncompleteBody
    78  	ErrInternalError
    79  	ErrInvalidAccessKeyID
    80  	ErrInvalidBucketName
    81  	ErrInvalidDigest
    82  	ErrInvalidRange
    83  	ErrInvalidRangePartNumber
    84  	ErrInvalidCopyPartRange
    85  	ErrInvalidCopyPartRangeSource
    86  	ErrInvalidMaxKeys
    87  	ErrInvalidEncodingMethod
    88  	ErrInvalidMaxUploads
    89  	ErrInvalidMaxParts
    90  	ErrInvalidPartNumberMarker
    91  	ErrInvalidPartNumber
    92  	ErrInvalidRequestBody
    93  	ErrInvalidCopySource
    94  	ErrInvalidMetadataDirective
    95  	ErrInvalidCopyDest
    96  	ErrInvalidPolicyDocument
    97  	ErrInvalidObjectState
    98  	ErrMalformedXML
    99  	ErrMissingContentLength
   100  	ErrMissingContentMD5
   101  	ErrMissingRequestBodyError
   102  	ErrMissingSecurityHeader
   103  	ErrNoSuchBucket
   104  	ErrNoSuchBucketPolicy
   105  	ErrNoSuchBucketLifecycle
   106  	ErrNoSuchLifecycleConfiguration
   107  	ErrNoSuchBucketSSEConfig
   108  	ErrNoSuchCORSConfiguration
   109  	ErrNoSuchWebsiteConfiguration
   110  	ErrReplicationConfigurationNotFoundError
   111  	ErrRemoteDestinationNotFoundError
   112  	ErrReplicationDestinationMissingLock
   113  	ErrRemoteTargetNotFoundError
   114  	ErrReplicationRemoteConnectionError
   115  	ErrBucketRemoteIdenticalToSource
   116  	ErrBucketRemoteAlreadyExists
   117  	ErrBucketRemoteLabelInUse
   118  	ErrBucketRemoteArnTypeInvalid
   119  	ErrBucketRemoteArnInvalid
   120  	ErrBucketRemoteRemoveDisallowed
   121  	ErrRemoteTargetNotVersionedError
   122  	ErrReplicationSourceNotVersionedError
   123  	ErrReplicationNeedsVersioningError
   124  	ErrReplicationBucketNeedsVersioningError
   125  	ErrObjectRestoreAlreadyInProgress
   126  	ErrNoSuchKey
   127  	ErrNoSuchUpload
   128  	ErrInvalidVersionID
   129  	ErrNoSuchVersion
   130  	ErrNotImplemented
   131  	ErrPreconditionFailed
   132  	ErrRequestTimeTooSkewed
   133  	ErrSignatureDoesNotMatch
   134  	ErrMethodNotAllowed
   135  	ErrInvalidPart
   136  	ErrInvalidPartOrder
   137  	ErrAuthorizationHeaderMalformed
   138  	ErrMalformedPOSTRequest
   139  	ErrPOSTFileRequired
   140  	ErrSignatureVersionNotSupported
   141  	ErrBucketNotEmpty
   142  	ErrAllAccessDisabled
   143  	ErrMalformedPolicy
   144  	ErrMissingFields
   145  	ErrMissingFieldsV2
   146  	ErrMissingCredTag
   147  	ErrCredMalformed
   148  	ErrInvalidRegion
   149  	ErrInvalidServiceS3
   150  	ErrInvalidServiceSTS
   151  	ErrInvalidRequestVersion
   152  	ErrMissingSignTag
   153  	ErrMissingSignHeadersTag
   154  	ErrMalformedDate
   155  	ErrMalformedPresignedDate
   156  	ErrMalformedCredentialDate
   157  	ErrMalformedCredentialRegion
   158  	ErrMalformedExpires
   159  	ErrNegativeExpires
   160  	ErrAuthHeaderEmpty
   161  	ErrExpiredPresignRequest
   162  	ErrRequestNotReadyYet
   163  	ErrUnsignedHeaders
   164  	ErrMissingDateHeader
   165  	ErrInvalidQuerySignatureAlgo
   166  	ErrInvalidQueryParams
   167  	ErrBucketAlreadyOwnedByYou
   168  	ErrInvalidDuration
   169  	ErrBucketAlreadyExists
   170  	ErrMetadataTooLarge
   171  	ErrUnsupportedMetadata
   172  	ErrMaximumExpires
   173  	ErrSlowDown
   174  	ErrInvalidPrefixMarker
   175  	ErrBadRequest
   176  	ErrKeyTooLongError
   177  	ErrInvalidBucketObjectLockConfiguration
   178  	ErrObjectLockConfigurationNotFound
   179  	ErrObjectLockConfigurationNotAllowed
   180  	ErrNoSuchObjectLockConfiguration
   181  	ErrObjectLocked
   182  	ErrInvalidRetentionDate
   183  	ErrPastObjectLockRetainDate
   184  	ErrUnknownWORMModeDirective
   185  	ErrBucketTaggingNotFound
   186  	ErrObjectLockInvalidHeaders
   187  	ErrInvalidTagDirective
   188  	// Add new error codes here.
   189  
   190  	// SSE-S3 related API errors
   191  	ErrInvalidEncryptionMethod
   192  
   193  	// Server-Side-Encryption (with Customer provided key) related API errors.
   194  	ErrInsecureSSECustomerRequest
   195  	ErrSSEMultipartEncrypted
   196  	ErrSSEEncryptedObject
   197  	ErrInvalidEncryptionParameters
   198  	ErrInvalidSSECustomerAlgorithm
   199  	ErrInvalidSSECustomerKey
   200  	ErrMissingSSECustomerKey
   201  	ErrMissingSSECustomerKeyMD5
   202  	ErrSSECustomerKeyMD5Mismatch
   203  	ErrInvalidSSECustomerParameters
   204  	ErrIncompatibleEncryptionMethod
   205  	ErrKMSNotConfigured
   206  
   207  	ErrNoAccessKey
   208  	ErrInvalidToken
   209  
   210  	// Bucket notification related errors.
   211  	ErrEventNotification
   212  	ErrARNNotification
   213  	ErrRegionNotification
   214  	ErrOverlappingFilterNotification
   215  	ErrFilterNameInvalid
   216  	ErrFilterNamePrefix
   217  	ErrFilterNameSuffix
   218  	ErrFilterValueInvalid
   219  	ErrOverlappingConfigs
   220  	ErrUnsupportedNotification
   221  
   222  	// S3 extended errors.
   223  	ErrContentSHA256Mismatch
   224  
   225  	// Add new extended error codes here.
   226  
   227  	// MinIO extended errors.
   228  	ErrReadQuorum
   229  	ErrWriteQuorum
   230  	ErrParentIsObject
   231  	ErrStorageFull
   232  	ErrRequestBodyParse
   233  	ErrObjectExistsAsDirectory
   234  	ErrInvalidObjectName
   235  	ErrInvalidObjectNamePrefixSlash
   236  	ErrInvalidResourceName
   237  	ErrServerNotInitialized
   238  	ErrOperationTimedOut
   239  	ErrClientDisconnected
   240  	ErrOperationMaxedOut
   241  	ErrInvalidRequest
   242  	// MinIO storage class error codes
   243  	ErrInvalidStorageClass
   244  	ErrBackendDown
   245  	// Add new extended error codes here.
   246  	// Please open a https://github.com/minio/minio/issues before adding
   247  	// new error codes here.
   248  
   249  	ErrMalformedJSON
   250  	ErrAdminNoSuchUser
   251  	ErrAdminNoSuchGroup
   252  	ErrAdminGroupNotEmpty
   253  	ErrAdminNoSuchPolicy
   254  	ErrAdminInvalidArgument
   255  	ErrAdminInvalidAccessKey
   256  	ErrAdminInvalidSecretKey
   257  	ErrAdminConfigNoQuorum
   258  	ErrAdminConfigTooLarge
   259  	ErrAdminConfigBadJSON
   260  	ErrAdminConfigDuplicateKeys
   261  	ErrAdminCredentialsMismatch
   262  	ErrInsecureClientRequest
   263  	ErrObjectTampered
   264  	// Bucket Quota error codes
   265  	ErrAdminBucketQuotaExceeded
   266  	ErrAdminNoSuchQuotaConfiguration
   267  
   268  	ErrHealNotImplemented
   269  	ErrHealNoSuchProcess
   270  	ErrHealInvalidClientToken
   271  	ErrHealMissingBucket
   272  	ErrHealAlreadyRunning
   273  	ErrHealOverlappingPaths
   274  	ErrIncorrectContinuationToken
   275  
   276  	// S3 Select Errors
   277  	ErrEmptyRequestBody
   278  	ErrUnsupportedFunction
   279  	ErrInvalidExpressionType
   280  	ErrBusy
   281  	ErrUnauthorizedAccess
   282  	ErrExpressionTooLong
   283  	ErrIllegalSQLFunctionArgument
   284  	ErrInvalidKeyPath
   285  	ErrInvalidCompressionFormat
   286  	ErrInvalidFileHeaderInfo
   287  	ErrInvalidJSONType
   288  	ErrInvalidQuoteFields
   289  	ErrInvalidRequestParameter
   290  	ErrInvalidDataType
   291  	ErrInvalidTextEncoding
   292  	ErrInvalidDataSource
   293  	ErrInvalidTableAlias
   294  	ErrMissingRequiredParameter
   295  	ErrObjectSerializationConflict
   296  	ErrUnsupportedSQLOperation
   297  	ErrUnsupportedSQLStructure
   298  	ErrUnsupportedSyntax
   299  	ErrUnsupportedRangeHeader
   300  	ErrLexerInvalidChar
   301  	ErrLexerInvalidOperator
   302  	ErrLexerInvalidLiteral
   303  	ErrLexerInvalidIONLiteral
   304  	ErrParseExpectedDatePart
   305  	ErrParseExpectedKeyword
   306  	ErrParseExpectedTokenType
   307  	ErrParseExpected2TokenTypes
   308  	ErrParseExpectedNumber
   309  	ErrParseExpectedRightParenBuiltinFunctionCall
   310  	ErrParseExpectedTypeName
   311  	ErrParseExpectedWhenClause
   312  	ErrParseUnsupportedToken
   313  	ErrParseUnsupportedLiteralsGroupBy
   314  	ErrParseExpectedMember
   315  	ErrParseUnsupportedSelect
   316  	ErrParseUnsupportedCase
   317  	ErrParseUnsupportedCaseClause
   318  	ErrParseUnsupportedAlias
   319  	ErrParseUnsupportedSyntax
   320  	ErrParseUnknownOperator
   321  	ErrParseMissingIdentAfterAt
   322  	ErrParseUnexpectedOperator
   323  	ErrParseUnexpectedTerm
   324  	ErrParseUnexpectedToken
   325  	ErrParseUnexpectedKeyword
   326  	ErrParseExpectedExpression
   327  	ErrParseExpectedLeftParenAfterCast
   328  	ErrParseExpectedLeftParenValueConstructor
   329  	ErrParseExpectedLeftParenBuiltinFunctionCall
   330  	ErrParseExpectedArgumentDelimiter
   331  	ErrParseCastArity
   332  	ErrParseInvalidTypeParam
   333  	ErrParseEmptySelect
   334  	ErrParseSelectMissingFrom
   335  	ErrParseExpectedIdentForGroupName
   336  	ErrParseExpectedIdentForAlias
   337  	ErrParseUnsupportedCallWithStar
   338  	ErrParseNonUnaryAgregateFunctionCall
   339  	ErrParseMalformedJoin
   340  	ErrParseExpectedIdentForAt
   341  	ErrParseAsteriskIsNotAloneInSelectList
   342  	ErrParseCannotMixSqbAndWildcardInSelectList
   343  	ErrParseInvalidContextForWildcardInSelectList
   344  	ErrIncorrectSQLFunctionArgumentType
   345  	ErrValueParseFailure
   346  	ErrEvaluatorInvalidArguments
   347  	ErrIntegerOverflow
   348  	ErrLikeInvalidInputs
   349  	ErrCastFailed
   350  	ErrInvalidCast
   351  	ErrEvaluatorInvalidTimestampFormatPattern
   352  	ErrEvaluatorInvalidTimestampFormatPatternSymbolForParsing
   353  	ErrEvaluatorTimestampFormatPatternDuplicateFields
   354  	ErrEvaluatorTimestampFormatPatternHourClockAmPmMismatch
   355  	ErrEvaluatorUnterminatedTimestampFormatPatternToken
   356  	ErrEvaluatorInvalidTimestampFormatPatternToken
   357  	ErrEvaluatorInvalidTimestampFormatPatternSymbol
   358  	ErrEvaluatorBindingDoesNotExist
   359  	ErrMissingHeaders
   360  	ErrInvalidColumnIndex
   361  
   362  	ErrAdminConfigNotificationTargetsFailed
   363  	ErrAdminProfilerNotEnabled
   364  	ErrInvalidDecompressedSize
   365  	ErrAddUserInvalidArgument
   366  	ErrAdminAccountNotEligible
   367  	ErrAccountNotEligible
   368  	ErrAdminServiceAccountNotFound
   369  	ErrPostPolicyConditionInvalidFormat
   370  )
   371  
   372  type errorCodeMap map[APIErrorCode]APIError
   373  
   374  func (e errorCodeMap) ToAPIErrWithErr(errCode APIErrorCode, err error) APIError {
   375  	apiErr, ok := e[errCode]
   376  	if !ok {
   377  		apiErr = e[ErrInternalError]
   378  	}
   379  	if err != nil {
   380  		apiErr.Description = fmt.Sprintf("%s (%s)", apiErr.Description, err)
   381  	}
   382  	if globalServerRegion != "" {
   383  		switch errCode {
   384  		case ErrAuthorizationHeaderMalformed:
   385  			apiErr.Description = fmt.Sprintf("The authorization header is malformed; the region is wrong; expecting '%s'.", globalServerRegion)
   386  			return apiErr
   387  		}
   388  	}
   389  	return apiErr
   390  }
   391  
   392  func (e errorCodeMap) ToAPIErr(errCode APIErrorCode) APIError {
   393  	return e.ToAPIErrWithErr(errCode, nil)
   394  }
   395  
   396  // error code to APIError structure, these fields carry respective
   397  // descriptions for all the error responses.
   398  var errorCodes = errorCodeMap{
   399  	ErrInvalidCopyDest: {
   400  		Code:           "InvalidRequest",
   401  		Description:    "This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class, website redirect location or encryption attributes.",
   402  		HTTPStatusCode: http.StatusBadRequest,
   403  	},
   404  	ErrInvalidCopySource: {
   405  		Code:           "InvalidArgument",
   406  		Description:    "Copy Source must mention the source bucket and key: sourcebucket/sourcekey.",
   407  		HTTPStatusCode: http.StatusBadRequest,
   408  	},
   409  	ErrInvalidMetadataDirective: {
   410  		Code:           "InvalidArgument",
   411  		Description:    "Unknown metadata directive.",
   412  		HTTPStatusCode: http.StatusBadRequest,
   413  	},
   414  	ErrInvalidStorageClass: {
   415  		Code:           "InvalidStorageClass",
   416  		Description:    "Invalid storage class.",
   417  		HTTPStatusCode: http.StatusBadRequest,
   418  	},
   419  	ErrInvalidRequestBody: {
   420  		Code:           "InvalidArgument",
   421  		Description:    "Body shouldn't be set for this request.",
   422  		HTTPStatusCode: http.StatusBadRequest,
   423  	},
   424  	ErrInvalidMaxUploads: {
   425  		Code:           "InvalidArgument",
   426  		Description:    "Argument max-uploads must be an integer between 0 and 2147483647",
   427  		HTTPStatusCode: http.StatusBadRequest,
   428  	},
   429  	ErrInvalidMaxKeys: {
   430  		Code:           "InvalidArgument",
   431  		Description:    "Argument maxKeys must be an integer between 0 and 2147483647",
   432  		HTTPStatusCode: http.StatusBadRequest,
   433  	},
   434  	ErrInvalidEncodingMethod: {
   435  		Code:           "InvalidArgument",
   436  		Description:    "Invalid Encoding Method specified in Request",
   437  		HTTPStatusCode: http.StatusBadRequest,
   438  	},
   439  	ErrInvalidMaxParts: {
   440  		Code:           "InvalidArgument",
   441  		Description:    "Argument max-parts must be an integer between 0 and 2147483647",
   442  		HTTPStatusCode: http.StatusBadRequest,
   443  	},
   444  	ErrInvalidPartNumberMarker: {
   445  		Code:           "InvalidArgument",
   446  		Description:    "Argument partNumberMarker must be an integer.",
   447  		HTTPStatusCode: http.StatusBadRequest,
   448  	},
   449  	ErrInvalidPartNumber: {
   450  		Code:           "InvalidPartNumber",
   451  		Description:    "The requested partnumber is not satisfiable",
   452  		HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable,
   453  	},
   454  	ErrInvalidPolicyDocument: {
   455  		Code:           "InvalidPolicyDocument",
   456  		Description:    "The content of the form does not meet the conditions specified in the policy document.",
   457  		HTTPStatusCode: http.StatusBadRequest,
   458  	},
   459  	ErrAccessDenied: {
   460  		Code:           "AccessDenied",
   461  		Description:    "Access Denied.",
   462  		HTTPStatusCode: http.StatusForbidden,
   463  	},
   464  	ErrBadDigest: {
   465  		Code:           "BadDigest",
   466  		Description:    "The Content-Md5 you specified did not match what we received.",
   467  		HTTPStatusCode: http.StatusBadRequest,
   468  	},
   469  	ErrEntityTooSmall: {
   470  		Code:           "EntityTooSmall",
   471  		Description:    "Your proposed upload is smaller than the minimum allowed object size.",
   472  		HTTPStatusCode: http.StatusBadRequest,
   473  	},
   474  	ErrEntityTooLarge: {
   475  		Code:           "EntityTooLarge",
   476  		Description:    "Your proposed upload exceeds the maximum allowed object size.",
   477  		HTTPStatusCode: http.StatusBadRequest,
   478  	},
   479  	ErrPolicyTooLarge: {
   480  		Code:           "PolicyTooLarge",
   481  		Description:    "Policy exceeds the maximum allowed document size.",
   482  		HTTPStatusCode: http.StatusBadRequest,
   483  	},
   484  	ErrIncompleteBody: {
   485  		Code:           "IncompleteBody",
   486  		Description:    "You did not provide the number of bytes specified by the Content-Length HTTP header.",
   487  		HTTPStatusCode: http.StatusBadRequest,
   488  	},
   489  	ErrInternalError: {
   490  		Code:           "InternalError",
   491  		Description:    "We encountered an internal error, please try again.",
   492  		HTTPStatusCode: http.StatusInternalServerError,
   493  	},
   494  	ErrInvalidAccessKeyID: {
   495  		Code:           "InvalidAccessKeyId",
   496  		Description:    "The Access Key Id you provided does not exist in our records.",
   497  		HTTPStatusCode: http.StatusForbidden,
   498  	},
   499  	ErrInvalidBucketName: {
   500  		Code:           "InvalidBucketName",
   501  		Description:    "The specified bucket is not valid.",
   502  		HTTPStatusCode: http.StatusBadRequest,
   503  	},
   504  	ErrInvalidDigest: {
   505  		Code:           "InvalidDigest",
   506  		Description:    "The Content-Md5 you specified is not valid.",
   507  		HTTPStatusCode: http.StatusBadRequest,
   508  	},
   509  	ErrInvalidRange: {
   510  		Code:           "InvalidRange",
   511  		Description:    "The requested range is not satisfiable",
   512  		HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable,
   513  	},
   514  	ErrInvalidRangePartNumber: {
   515  		Code:           "InvalidRequest",
   516  		Description:    "Cannot specify both Range header and partNumber query parameter",
   517  		HTTPStatusCode: http.StatusBadRequest,
   518  	},
   519  	ErrMalformedXML: {
   520  		Code:           "MalformedXML",
   521  		Description:    "The XML you provided was not well-formed or did not validate against our published schema.",
   522  		HTTPStatusCode: http.StatusBadRequest,
   523  	},
   524  	ErrMissingContentLength: {
   525  		Code:           "MissingContentLength",
   526  		Description:    "You must provide the Content-Length HTTP header.",
   527  		HTTPStatusCode: http.StatusLengthRequired,
   528  	},
   529  	ErrMissingContentMD5: {
   530  		Code:           "MissingContentMD5",
   531  		Description:    "Missing required header for this request: Content-Md5.",
   532  		HTTPStatusCode: http.StatusBadRequest,
   533  	},
   534  	ErrMissingSecurityHeader: {
   535  		Code:           "MissingSecurityHeader",
   536  		Description:    "Your request was missing a required header",
   537  		HTTPStatusCode: http.StatusBadRequest,
   538  	},
   539  	ErrMissingRequestBodyError: {
   540  		Code:           "MissingRequestBodyError",
   541  		Description:    "Request body is empty.",
   542  		HTTPStatusCode: http.StatusLengthRequired,
   543  	},
   544  	ErrNoSuchBucket: {
   545  		Code:           "NoSuchBucket",
   546  		Description:    "The specified bucket does not exist",
   547  		HTTPStatusCode: http.StatusNotFound,
   548  	},
   549  	ErrNoSuchBucketPolicy: {
   550  		Code:           "NoSuchBucketPolicy",
   551  		Description:    "The bucket policy does not exist",
   552  		HTTPStatusCode: http.StatusNotFound,
   553  	},
   554  	ErrNoSuchBucketLifecycle: {
   555  		Code:           "NoSuchBucketLifecycle",
   556  		Description:    "The bucket lifecycle configuration does not exist",
   557  		HTTPStatusCode: http.StatusNotFound,
   558  	},
   559  	ErrNoSuchLifecycleConfiguration: {
   560  		Code:           "NoSuchLifecycleConfiguration",
   561  		Description:    "The lifecycle configuration does not exist",
   562  		HTTPStatusCode: http.StatusNotFound,
   563  	},
   564  	ErrNoSuchBucketSSEConfig: {
   565  		Code:           "ServerSideEncryptionConfigurationNotFoundError",
   566  		Description:    "The server side encryption configuration was not found",
   567  		HTTPStatusCode: http.StatusNotFound,
   568  	},
   569  	ErrNoSuchKey: {
   570  		Code:           "NoSuchKey",
   571  		Description:    "The specified key does not exist.",
   572  		HTTPStatusCode: http.StatusNotFound,
   573  	},
   574  	ErrNoSuchUpload: {
   575  		Code:           "NoSuchUpload",
   576  		Description:    "The specified multipart upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.",
   577  		HTTPStatusCode: http.StatusNotFound,
   578  	},
   579  	ErrInvalidVersionID: {
   580  		Code:           "InvalidArgument",
   581  		Description:    "Invalid version id specified",
   582  		HTTPStatusCode: http.StatusBadRequest,
   583  	},
   584  	ErrNoSuchVersion: {
   585  		Code:           "NoSuchVersion",
   586  		Description:    "The specified version does not exist.",
   587  		HTTPStatusCode: http.StatusNotFound,
   588  	},
   589  	ErrNotImplemented: {
   590  		Code:           "NotImplemented",
   591  		Description:    "A header you provided implies functionality that is not implemented",
   592  		HTTPStatusCode: http.StatusNotImplemented,
   593  	},
   594  	ErrPreconditionFailed: {
   595  		Code:           "PreconditionFailed",
   596  		Description:    "At least one of the pre-conditions you specified did not hold",
   597  		HTTPStatusCode: http.StatusPreconditionFailed,
   598  	},
   599  	ErrRequestTimeTooSkewed: {
   600  		Code:           "RequestTimeTooSkewed",
   601  		Description:    "The difference between the request time and the server's time is too large.",
   602  		HTTPStatusCode: http.StatusForbidden,
   603  	},
   604  	ErrSignatureDoesNotMatch: {
   605  		Code:           "SignatureDoesNotMatch",
   606  		Description:    "The request signature we calculated does not match the signature you provided. Check your key and signing method.",
   607  		HTTPStatusCode: http.StatusForbidden,
   608  	},
   609  	ErrMethodNotAllowed: {
   610  		Code:           "MethodNotAllowed",
   611  		Description:    "The specified method is not allowed against this resource.",
   612  		HTTPStatusCode: http.StatusMethodNotAllowed,
   613  	},
   614  	ErrInvalidPart: {
   615  		Code:           "InvalidPart",
   616  		Description:    "One or more of the specified parts could not be found.  The part may not have been uploaded, or the specified entity tag may not match the part's entity tag.",
   617  		HTTPStatusCode: http.StatusBadRequest,
   618  	},
   619  	ErrInvalidPartOrder: {
   620  		Code:           "InvalidPartOrder",
   621  		Description:    "The list of parts was not in ascending order. The parts list must be specified in order by part number.",
   622  		HTTPStatusCode: http.StatusBadRequest,
   623  	},
   624  	ErrInvalidObjectState: {
   625  		Code:           "InvalidObjectState",
   626  		Description:    "The operation is not valid for the current state of the object.",
   627  		HTTPStatusCode: http.StatusForbidden,
   628  	},
   629  	ErrAuthorizationHeaderMalformed: {
   630  		Code:           "AuthorizationHeaderMalformed",
   631  		Description:    "The authorization header is malformed; the region is wrong; expecting 'us-east-1'.",
   632  		HTTPStatusCode: http.StatusBadRequest,
   633  	},
   634  	ErrMalformedPOSTRequest: {
   635  		Code:           "MalformedPOSTRequest",
   636  		Description:    "The body of your POST request is not well-formed multipart/form-data.",
   637  		HTTPStatusCode: http.StatusBadRequest,
   638  	},
   639  	ErrPOSTFileRequired: {
   640  		Code:           "InvalidArgument",
   641  		Description:    "POST requires exactly one file upload per request.",
   642  		HTTPStatusCode: http.StatusBadRequest,
   643  	},
   644  	ErrSignatureVersionNotSupported: {
   645  		Code:           "InvalidRequest",
   646  		Description:    "The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.",
   647  		HTTPStatusCode: http.StatusBadRequest,
   648  	},
   649  	ErrBucketNotEmpty: {
   650  		Code:           "BucketNotEmpty",
   651  		Description:    "The bucket you tried to delete is not empty",
   652  		HTTPStatusCode: http.StatusConflict,
   653  	},
   654  	ErrBucketAlreadyExists: {
   655  		Code:           "BucketAlreadyExists",
   656  		Description:    "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.",
   657  		HTTPStatusCode: http.StatusConflict,
   658  	},
   659  	ErrAllAccessDisabled: {
   660  		Code:           "AllAccessDisabled",
   661  		Description:    "All access to this bucket has been disabled.",
   662  		HTTPStatusCode: http.StatusForbidden,
   663  	},
   664  	ErrMalformedPolicy: {
   665  		Code:           "MalformedPolicy",
   666  		Description:    "Policy has invalid resource.",
   667  		HTTPStatusCode: http.StatusBadRequest,
   668  	},
   669  	ErrMissingFields: {
   670  		Code:           "MissingFields",
   671  		Description:    "Missing fields in request.",
   672  		HTTPStatusCode: http.StatusBadRequest,
   673  	},
   674  	ErrMissingFieldsV2: {
   675  		Code:           "InvalidArgument",
   676  		Description:    "AWS authorization header is invalid.  Expected AwsAccessKeyId:signature",
   677  		HTTPStatusCode: http.StatusBadRequest,
   678  	},
   679  	ErrMissingCredTag: {
   680  		Code:           "InvalidRequest",
   681  		Description:    "Missing Credential field for this request.",
   682  		HTTPStatusCode: http.StatusBadRequest,
   683  	},
   684  	ErrCredMalformed: {
   685  		Code:           "AuthorizationQueryParametersError",
   686  		Description:    "Error parsing the X-Amz-Credential parameter; the Credential is mal-formed; expecting \"<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request\".",
   687  		HTTPStatusCode: http.StatusBadRequest,
   688  	},
   689  	ErrMalformedDate: {
   690  		Code:           "MalformedDate",
   691  		Description:    "Invalid date format header, expected to be in ISO8601, RFC1123 or RFC1123Z time format.",
   692  		HTTPStatusCode: http.StatusBadRequest,
   693  	},
   694  	ErrMalformedPresignedDate: {
   695  		Code:           "AuthorizationQueryParametersError",
   696  		Description:    "X-Amz-Date must be in the ISO8601 Long Format \"yyyyMMdd'T'HHmmss'Z'\"",
   697  		HTTPStatusCode: http.StatusBadRequest,
   698  	},
   699  	ErrMalformedCredentialDate: {
   700  		Code:           "AuthorizationQueryParametersError",
   701  		Description:    "Error parsing the X-Amz-Credential parameter; incorrect date format. This date in the credential must be in the format \"yyyyMMdd\".",
   702  		HTTPStatusCode: http.StatusBadRequest,
   703  	},
   704  	ErrInvalidRegion: {
   705  		Code:           "InvalidRegion",
   706  		Description:    "Region does not match.",
   707  		HTTPStatusCode: http.StatusBadRequest,
   708  	},
   709  	ErrInvalidServiceS3: {
   710  		Code:           "AuthorizationParametersError",
   711  		Description:    "Error parsing the Credential/X-Amz-Credential parameter; incorrect service. This endpoint belongs to \"s3\".",
   712  		HTTPStatusCode: http.StatusBadRequest,
   713  	},
   714  	ErrInvalidServiceSTS: {
   715  		Code:           "AuthorizationParametersError",
   716  		Description:    "Error parsing the Credential parameter; incorrect service. This endpoint belongs to \"sts\".",
   717  		HTTPStatusCode: http.StatusBadRequest,
   718  	},
   719  	ErrInvalidRequestVersion: {
   720  		Code:           "AuthorizationQueryParametersError",
   721  		Description:    "Error parsing the X-Amz-Credential parameter; incorrect terminal. This endpoint uses \"aws4_request\".",
   722  		HTTPStatusCode: http.StatusBadRequest,
   723  	},
   724  	ErrMissingSignTag: {
   725  		Code:           "AccessDenied",
   726  		Description:    "Signature header missing Signature field.",
   727  		HTTPStatusCode: http.StatusBadRequest,
   728  	},
   729  	ErrMissingSignHeadersTag: {
   730  		Code:           "InvalidArgument",
   731  		Description:    "Signature header missing SignedHeaders field.",
   732  		HTTPStatusCode: http.StatusBadRequest,
   733  	},
   734  	ErrMalformedExpires: {
   735  		Code:           "AuthorizationQueryParametersError",
   736  		Description:    "X-Amz-Expires should be a number",
   737  		HTTPStatusCode: http.StatusBadRequest,
   738  	},
   739  	ErrNegativeExpires: {
   740  		Code:           "AuthorizationQueryParametersError",
   741  		Description:    "X-Amz-Expires must be non-negative",
   742  		HTTPStatusCode: http.StatusBadRequest,
   743  	},
   744  	ErrAuthHeaderEmpty: {
   745  		Code:           "InvalidArgument",
   746  		Description:    "Authorization header is invalid -- one and only one ' ' (space) required.",
   747  		HTTPStatusCode: http.StatusBadRequest,
   748  	},
   749  	ErrMissingDateHeader: {
   750  		Code:           "AccessDenied",
   751  		Description:    "AWS authentication requires a valid Date or x-amz-date header",
   752  		HTTPStatusCode: http.StatusForbidden,
   753  	},
   754  	ErrInvalidQuerySignatureAlgo: {
   755  		Code:           "AuthorizationQueryParametersError",
   756  		Description:    "X-Amz-Algorithm only supports \"AWS4-HMAC-SHA256\".",
   757  		HTTPStatusCode: http.StatusBadRequest,
   758  	},
   759  	ErrExpiredPresignRequest: {
   760  		Code:           "AccessDenied",
   761  		Description:    "Request has expired",
   762  		HTTPStatusCode: http.StatusForbidden,
   763  	},
   764  	ErrRequestNotReadyYet: {
   765  		Code:           "AccessDenied",
   766  		Description:    "Request is not valid yet",
   767  		HTTPStatusCode: http.StatusForbidden,
   768  	},
   769  	ErrSlowDown: {
   770  		Code:           "SlowDown",
   771  		Description:    "Please reduce your request",
   772  		HTTPStatusCode: http.StatusServiceUnavailable,
   773  	},
   774  	ErrInvalidPrefixMarker: {
   775  		Code:           "InvalidPrefixMarker",
   776  		Description:    "Invalid marker prefix combination",
   777  		HTTPStatusCode: http.StatusBadRequest,
   778  	},
   779  	ErrBadRequest: {
   780  		Code:           "BadRequest",
   781  		Description:    "400 BadRequest",
   782  		HTTPStatusCode: http.StatusBadRequest,
   783  	},
   784  	ErrKeyTooLongError: {
   785  		Code:           "KeyTooLongError",
   786  		Description:    "Your key is too long",
   787  		HTTPStatusCode: http.StatusBadRequest,
   788  	},
   789  	ErrUnsignedHeaders: {
   790  		Code:           "AccessDenied",
   791  		Description:    "There were headers present in the request which were not signed",
   792  		HTTPStatusCode: http.StatusBadRequest,
   793  	},
   794  	ErrInvalidQueryParams: {
   795  		Code:           "AuthorizationQueryParametersError",
   796  		Description:    "Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.",
   797  		HTTPStatusCode: http.StatusBadRequest,
   798  	},
   799  	ErrBucketAlreadyOwnedByYou: {
   800  		Code:           "BucketAlreadyOwnedByYou",
   801  		Description:    "Your previous request to create the named bucket succeeded and you already own it.",
   802  		HTTPStatusCode: http.StatusConflict,
   803  	},
   804  	ErrInvalidDuration: {
   805  		Code:           "InvalidDuration",
   806  		Description:    "Duration provided in the request is invalid.",
   807  		HTTPStatusCode: http.StatusBadRequest,
   808  	},
   809  	ErrInvalidBucketObjectLockConfiguration: {
   810  		Code:           "InvalidRequest",
   811  		Description:    "Bucket is missing ObjectLockConfiguration",
   812  		HTTPStatusCode: http.StatusBadRequest,
   813  	},
   814  	ErrBucketTaggingNotFound: {
   815  		Code:           "NoSuchTagSet",
   816  		Description:    "The TagSet does not exist",
   817  		HTTPStatusCode: http.StatusNotFound,
   818  	},
   819  	ErrObjectLockConfigurationNotFound: {
   820  		Code:           "ObjectLockConfigurationNotFoundError",
   821  		Description:    "Object Lock configuration does not exist for this bucket",
   822  		HTTPStatusCode: http.StatusNotFound,
   823  	},
   824  	ErrObjectLockConfigurationNotAllowed: {
   825  		Code:           "InvalidBucketState",
   826  		Description:    "Object Lock configuration cannot be enabled on existing buckets",
   827  		HTTPStatusCode: http.StatusConflict,
   828  	},
   829  	ErrNoSuchCORSConfiguration: {
   830  		Code:           "NoSuchCORSConfiguration",
   831  		Description:    "The CORS configuration does not exist",
   832  		HTTPStatusCode: http.StatusNotFound,
   833  	},
   834  	ErrNoSuchWebsiteConfiguration: {
   835  		Code:           "NoSuchWebsiteConfiguration",
   836  		Description:    "The specified bucket does not have a website configuration",
   837  		HTTPStatusCode: http.StatusNotFound,
   838  	},
   839  	ErrReplicationConfigurationNotFoundError: {
   840  		Code:           "ReplicationConfigurationNotFoundError",
   841  		Description:    "The replication configuration was not found",
   842  		HTTPStatusCode: http.StatusNotFound,
   843  	},
   844  	ErrRemoteDestinationNotFoundError: {
   845  		Code:           "RemoteDestinationNotFoundError",
   846  		Description:    "The remote destination bucket does not exist",
   847  		HTTPStatusCode: http.StatusNotFound,
   848  	},
   849  	ErrReplicationDestinationMissingLock: {
   850  		Code:           "ReplicationDestinationMissingLockError",
   851  		Description:    "The replication destination bucket does not have object locking enabled",
   852  		HTTPStatusCode: http.StatusBadRequest,
   853  	},
   854  	ErrRemoteTargetNotFoundError: {
   855  		Code:           "XMinioAdminRemoteTargetNotFoundError",
   856  		Description:    "The remote target does not exist",
   857  		HTTPStatusCode: http.StatusNotFound,
   858  	},
   859  	ErrReplicationRemoteConnectionError: {
   860  		Code:           "XMinioAdminReplicationRemoteConnectionError",
   861  		Description:    "Remote service connection error - please check remote service credentials and target bucket",
   862  		HTTPStatusCode: http.StatusNotFound,
   863  	},
   864  	ErrBucketRemoteIdenticalToSource: {
   865  		Code:           "XMinioAdminRemoteIdenticalToSource",
   866  		Description:    "The remote target cannot be identical to source",
   867  		HTTPStatusCode: http.StatusBadRequest,
   868  	},
   869  	ErrBucketRemoteAlreadyExists: {
   870  		Code:           "XMinioAdminBucketRemoteAlreadyExists",
   871  		Description:    "The remote target already exists",
   872  		HTTPStatusCode: http.StatusBadRequest,
   873  	},
   874  	ErrBucketRemoteLabelInUse: {
   875  		Code:           "XMinioAdminBucketRemoteLabelInUse",
   876  		Description:    "The remote target with this label already exists",
   877  		HTTPStatusCode: http.StatusBadRequest,
   878  	},
   879  	ErrBucketRemoteRemoveDisallowed: {
   880  		Code:           "XMinioAdminRemoteRemoveDisallowed",
   881  		Description:    "This ARN is in use by an existing configuration",
   882  		HTTPStatusCode: http.StatusBadRequest,
   883  	},
   884  	ErrBucketRemoteArnTypeInvalid: {
   885  		Code:           "XMinioAdminRemoteARNTypeInvalid",
   886  		Description:    "The bucket remote ARN type is not valid",
   887  		HTTPStatusCode: http.StatusBadRequest,
   888  	},
   889  	ErrBucketRemoteArnInvalid: {
   890  		Code:           "XMinioAdminRemoteArnInvalid",
   891  		Description:    "The bucket remote ARN does not have correct format",
   892  		HTTPStatusCode: http.StatusBadRequest,
   893  	},
   894  	ErrRemoteTargetNotVersionedError: {
   895  		Code:           "RemoteTargetNotVersionedError",
   896  		Description:    "The remote target does not have versioning enabled",
   897  		HTTPStatusCode: http.StatusBadRequest,
   898  	},
   899  	ErrReplicationSourceNotVersionedError: {
   900  		Code:           "ReplicationSourceNotVersionedError",
   901  		Description:    "The replication source does not have versioning enabled",
   902  		HTTPStatusCode: http.StatusBadRequest,
   903  	},
   904  	ErrReplicationNeedsVersioningError: {
   905  		Code:           "InvalidRequest",
   906  		Description:    "Versioning must be 'Enabled' on the bucket to apply a replication configuration",
   907  		HTTPStatusCode: http.StatusBadRequest,
   908  	},
   909  	ErrReplicationBucketNeedsVersioningError: {
   910  		Code:           "InvalidRequest",
   911  		Description:    "Versioning must be 'Enabled' on the bucket to add a replication target",
   912  		HTTPStatusCode: http.StatusBadRequest,
   913  	},
   914  	ErrNoSuchObjectLockConfiguration: {
   915  		Code:           "NoSuchObjectLockConfiguration",
   916  		Description:    "The specified object does not have a ObjectLock configuration",
   917  		HTTPStatusCode: http.StatusBadRequest,
   918  	},
   919  	ErrObjectLocked: {
   920  		Code:           "InvalidRequest",
   921  		Description:    "Object is WORM protected and cannot be overwritten",
   922  		HTTPStatusCode: http.StatusBadRequest,
   923  	},
   924  	ErrInvalidRetentionDate: {
   925  		Code:           "InvalidRequest",
   926  		Description:    "Date must be provided in ISO 8601 format",
   927  		HTTPStatusCode: http.StatusBadRequest,
   928  	},
   929  	ErrPastObjectLockRetainDate: {
   930  		Code:           "InvalidRequest",
   931  		Description:    "the retain until date must be in the future",
   932  		HTTPStatusCode: http.StatusBadRequest,
   933  	},
   934  	ErrUnknownWORMModeDirective: {
   935  		Code:           "InvalidRequest",
   936  		Description:    "unknown wormMode directive",
   937  		HTTPStatusCode: http.StatusBadRequest,
   938  	},
   939  	ErrObjectLockInvalidHeaders: {
   940  		Code:           "InvalidRequest",
   941  		Description:    "x-amz-object-lock-retain-until-date and x-amz-object-lock-mode must both be supplied",
   942  		HTTPStatusCode: http.StatusBadRequest,
   943  	},
   944  	ErrObjectRestoreAlreadyInProgress: {
   945  		Code:           "RestoreAlreadyInProgress",
   946  		Description:    "Object restore is already in progress",
   947  		HTTPStatusCode: http.StatusConflict,
   948  	},
   949  	/// Bucket notification related errors.
   950  	ErrEventNotification: {
   951  		Code:           "InvalidArgument",
   952  		Description:    "A specified event is not supported for notifications.",
   953  		HTTPStatusCode: http.StatusBadRequest,
   954  	},
   955  	ErrARNNotification: {
   956  		Code:           "InvalidArgument",
   957  		Description:    "A specified destination ARN does not exist or is not well-formed. Verify the destination ARN.",
   958  		HTTPStatusCode: http.StatusBadRequest,
   959  	},
   960  	ErrRegionNotification: {
   961  		Code:           "InvalidArgument",
   962  		Description:    "A specified destination is in a different region than the bucket. You must use a destination that resides in the same region as the bucket.",
   963  		HTTPStatusCode: http.StatusBadRequest,
   964  	},
   965  	ErrOverlappingFilterNotification: {
   966  		Code:           "InvalidArgument",
   967  		Description:    "An object key name filtering rule defined with overlapping prefixes, overlapping suffixes, or overlapping combinations of prefixes and suffixes for the same event types.",
   968  		HTTPStatusCode: http.StatusBadRequest,
   969  	},
   970  	ErrFilterNameInvalid: {
   971  		Code:           "InvalidArgument",
   972  		Description:    "filter rule name must be either prefix or suffix",
   973  		HTTPStatusCode: http.StatusBadRequest,
   974  	},
   975  	ErrFilterNamePrefix: {
   976  		Code:           "InvalidArgument",
   977  		Description:    "Cannot specify more than one prefix rule in a filter.",
   978  		HTTPStatusCode: http.StatusBadRequest,
   979  	},
   980  	ErrFilterNameSuffix: {
   981  		Code:           "InvalidArgument",
   982  		Description:    "Cannot specify more than one suffix rule in a filter.",
   983  		HTTPStatusCode: http.StatusBadRequest,
   984  	},
   985  	ErrFilterValueInvalid: {
   986  		Code:           "InvalidArgument",
   987  		Description:    "Size of filter rule value cannot exceed 1024 bytes in UTF-8 representation",
   988  		HTTPStatusCode: http.StatusBadRequest,
   989  	},
   990  	ErrOverlappingConfigs: {
   991  		Code:           "InvalidArgument",
   992  		Description:    "Configurations overlap. Configurations on the same bucket cannot share a common event type.",
   993  		HTTPStatusCode: http.StatusBadRequest,
   994  	},
   995  	ErrUnsupportedNotification: {
   996  		Code:           "UnsupportedNotification",
   997  		Description:    "MinIO server does not support Topic or Cloud Function based notifications.",
   998  		HTTPStatusCode: http.StatusBadRequest,
   999  	},
  1000  	ErrInvalidCopyPartRange: {
  1001  		Code:           "InvalidArgument",
  1002  		Description:    "The x-amz-copy-source-range value must be of the form bytes=first-last where first and last are the zero-based offsets of the first and last bytes to copy",
  1003  		HTTPStatusCode: http.StatusBadRequest,
  1004  	},
  1005  	ErrInvalidCopyPartRangeSource: {
  1006  		Code:           "InvalidArgument",
  1007  		Description:    "Range specified is not valid for source object",
  1008  		HTTPStatusCode: http.StatusBadRequest,
  1009  	},
  1010  	ErrMetadataTooLarge: {
  1011  		Code:           "MetadataTooLarge",
  1012  		Description:    "Your metadata headers exceed the maximum allowed metadata size.",
  1013  		HTTPStatusCode: http.StatusBadRequest,
  1014  	},
  1015  	ErrInvalidTagDirective: {
  1016  		Code:           "InvalidArgument",
  1017  		Description:    "Unknown tag directive.",
  1018  		HTTPStatusCode: http.StatusBadRequest,
  1019  	},
  1020  	ErrInvalidEncryptionMethod: {
  1021  		Code:           "InvalidRequest",
  1022  		Description:    "The encryption method specified is not supported",
  1023  		HTTPStatusCode: http.StatusBadRequest,
  1024  	},
  1025  	ErrInsecureSSECustomerRequest: {
  1026  		Code:           "InvalidRequest",
  1027  		Description:    "Requests specifying Server Side Encryption with Customer provided keys must be made over a secure connection.",
  1028  		HTTPStatusCode: http.StatusBadRequest,
  1029  	},
  1030  	ErrSSEMultipartEncrypted: {
  1031  		Code:           "InvalidRequest",
  1032  		Description:    "The multipart upload initiate requested encryption. Subsequent part requests must include the appropriate encryption parameters.",
  1033  		HTTPStatusCode: http.StatusBadRequest,
  1034  	},
  1035  	ErrSSEEncryptedObject: {
  1036  		Code:           "InvalidRequest",
  1037  		Description:    "The object was stored using a form of Server Side Encryption. The correct parameters must be provided to retrieve the object.",
  1038  		HTTPStatusCode: http.StatusBadRequest,
  1039  	},
  1040  	ErrInvalidEncryptionParameters: {
  1041  		Code:           "InvalidRequest",
  1042  		Description:    "The encryption parameters are not applicable to this object.",
  1043  		HTTPStatusCode: http.StatusBadRequest,
  1044  	},
  1045  	ErrInvalidSSECustomerAlgorithm: {
  1046  		Code:           "InvalidArgument",
  1047  		Description:    "Requests specifying Server Side Encryption with Customer provided keys must provide a valid encryption algorithm.",
  1048  		HTTPStatusCode: http.StatusBadRequest,
  1049  	},
  1050  	ErrInvalidSSECustomerKey: {
  1051  		Code:           "InvalidArgument",
  1052  		Description:    "The secret key was invalid for the specified algorithm.",
  1053  		HTTPStatusCode: http.StatusBadRequest,
  1054  	},
  1055  	ErrMissingSSECustomerKey: {
  1056  		Code:           "InvalidArgument",
  1057  		Description:    "Requests specifying Server Side Encryption with Customer provided keys must provide an appropriate secret key.",
  1058  		HTTPStatusCode: http.StatusBadRequest,
  1059  	},
  1060  	ErrMissingSSECustomerKeyMD5: {
  1061  		Code:           "InvalidArgument",
  1062  		Description:    "Requests specifying Server Side Encryption with Customer provided keys must provide the client calculated MD5 of the secret key.",
  1063  		HTTPStatusCode: http.StatusBadRequest,
  1064  	},
  1065  	ErrSSECustomerKeyMD5Mismatch: {
  1066  		Code:           "InvalidArgument",
  1067  		Description:    "The calculated MD5 hash of the key did not match the hash that was provided.",
  1068  		HTTPStatusCode: http.StatusBadRequest,
  1069  	},
  1070  	ErrInvalidSSECustomerParameters: {
  1071  		Code:           "InvalidArgument",
  1072  		Description:    "The provided encryption parameters did not match the ones used originally.",
  1073  		HTTPStatusCode: http.StatusBadRequest,
  1074  	},
  1075  	ErrIncompatibleEncryptionMethod: {
  1076  		Code:           "InvalidArgument",
  1077  		Description:    "Server side encryption specified with both SSE-C and SSE-S3 headers",
  1078  		HTTPStatusCode: http.StatusBadRequest,
  1079  	},
  1080  	ErrKMSNotConfigured: {
  1081  		Code:           "InvalidArgument",
  1082  		Description:    "Server side encryption specified but KMS is not configured",
  1083  		HTTPStatusCode: http.StatusBadRequest,
  1084  	},
  1085  	ErrNoAccessKey: {
  1086  		Code:           "AccessDenied",
  1087  		Description:    "No AWSAccessKey was presented",
  1088  		HTTPStatusCode: http.StatusForbidden,
  1089  	},
  1090  	ErrInvalidToken: {
  1091  		Code:           "InvalidTokenId",
  1092  		Description:    "The security token included in the request is invalid",
  1093  		HTTPStatusCode: http.StatusForbidden,
  1094  	},
  1095  
  1096  	/// S3 extensions.
  1097  	ErrContentSHA256Mismatch: {
  1098  		Code:           "XAmzContentSHA256Mismatch",
  1099  		Description:    "The provided 'x-amz-content-sha256' header does not match what was computed.",
  1100  		HTTPStatusCode: http.StatusBadRequest,
  1101  	},
  1102  
  1103  	/// MinIO extensions.
  1104  	ErrStorageFull: {
  1105  		Code:           "XMinioStorageFull",
  1106  		Description:    "Storage backend has reached its minimum free disk threshold. Please delete a few objects to proceed.",
  1107  		HTTPStatusCode: http.StatusInsufficientStorage,
  1108  	},
  1109  	ErrParentIsObject: {
  1110  		Code:           "XMinioParentIsObject",
  1111  		Description:    "Object-prefix is already an object, please choose a different object-prefix name.",
  1112  		HTTPStatusCode: http.StatusBadRequest,
  1113  	},
  1114  	ErrRequestBodyParse: {
  1115  		Code:           "XMinioRequestBodyParse",
  1116  		Description:    "The request body failed to parse.",
  1117  		HTTPStatusCode: http.StatusBadRequest,
  1118  	},
  1119  	ErrObjectExistsAsDirectory: {
  1120  		Code:           "XMinioObjectExistsAsDirectory",
  1121  		Description:    "Object name already exists as a directory.",
  1122  		HTTPStatusCode: http.StatusConflict,
  1123  	},
  1124  	ErrInvalidObjectName: {
  1125  		Code:           "XMinioInvalidObjectName",
  1126  		Description:    "Object name contains unsupported characters.",
  1127  		HTTPStatusCode: http.StatusBadRequest,
  1128  	},
  1129  	ErrInvalidObjectNamePrefixSlash: {
  1130  		Code:           "XMinioInvalidObjectName",
  1131  		Description:    "Object name contains a leading slash.",
  1132  		HTTPStatusCode: http.StatusBadRequest,
  1133  	},
  1134  	ErrInvalidResourceName: {
  1135  		Code:           "XMinioInvalidResourceName",
  1136  		Description:    "Resource name contains bad components such as \"..\" or \".\".",
  1137  		HTTPStatusCode: http.StatusBadRequest,
  1138  	},
  1139  	ErrServerNotInitialized: {
  1140  		Code:           "XMinioServerNotInitialized",
  1141  		Description:    "Server not initialized, please try again.",
  1142  		HTTPStatusCode: http.StatusServiceUnavailable,
  1143  	},
  1144  	ErrMalformedJSON: {
  1145  		Code:           "XMinioMalformedJSON",
  1146  		Description:    "The JSON you provided was not well-formed or did not validate against our published format.",
  1147  		HTTPStatusCode: http.StatusBadRequest,
  1148  	},
  1149  	ErrAdminNoSuchUser: {
  1150  		Code:           "XMinioAdminNoSuchUser",
  1151  		Description:    "The specified user does not exist.",
  1152  		HTTPStatusCode: http.StatusNotFound,
  1153  	},
  1154  	ErrAdminNoSuchGroup: {
  1155  		Code:           "XMinioAdminNoSuchGroup",
  1156  		Description:    "The specified group does not exist.",
  1157  		HTTPStatusCode: http.StatusNotFound,
  1158  	},
  1159  	ErrAdminGroupNotEmpty: {
  1160  		Code:           "XMinioAdminGroupNotEmpty",
  1161  		Description:    "The specified group is not empty - cannot remove it.",
  1162  		HTTPStatusCode: http.StatusBadRequest,
  1163  	},
  1164  	ErrAdminNoSuchPolicy: {
  1165  		Code:           "XMinioAdminNoSuchPolicy",
  1166  		Description:    "The canned policy does not exist.",
  1167  		HTTPStatusCode: http.StatusNotFound,
  1168  	},
  1169  	ErrAdminInvalidArgument: {
  1170  		Code:           "XMinioAdminInvalidArgument",
  1171  		Description:    "Invalid arguments specified.",
  1172  		HTTPStatusCode: http.StatusBadRequest,
  1173  	},
  1174  	ErrAdminInvalidAccessKey: {
  1175  		Code:           "XMinioAdminInvalidAccessKey",
  1176  		Description:    "The access key is invalid.",
  1177  		HTTPStatusCode: http.StatusBadRequest,
  1178  	},
  1179  	ErrAdminInvalidSecretKey: {
  1180  		Code:           "XMinioAdminInvalidSecretKey",
  1181  		Description:    "The secret key is invalid.",
  1182  		HTTPStatusCode: http.StatusBadRequest,
  1183  	},
  1184  	ErrAdminConfigNoQuorum: {
  1185  		Code:           "XMinioAdminConfigNoQuorum",
  1186  		Description:    "Configuration update failed because server quorum was not met",
  1187  		HTTPStatusCode: http.StatusServiceUnavailable,
  1188  	},
  1189  	ErrAdminConfigTooLarge: {
  1190  		Code: "XMinioAdminConfigTooLarge",
  1191  		Description: fmt.Sprintf("Configuration data provided exceeds the allowed maximum of %d bytes",
  1192  			maxEConfigJSONSize),
  1193  		HTTPStatusCode: http.StatusBadRequest,
  1194  	},
  1195  	ErrAdminConfigBadJSON: {
  1196  		Code:           "XMinioAdminConfigBadJSON",
  1197  		Description:    "JSON configuration provided is of incorrect format",
  1198  		HTTPStatusCode: http.StatusBadRequest,
  1199  	},
  1200  	ErrAdminConfigDuplicateKeys: {
  1201  		Code:           "XMinioAdminConfigDuplicateKeys",
  1202  		Description:    "JSON configuration provided has objects with duplicate keys",
  1203  		HTTPStatusCode: http.StatusBadRequest,
  1204  	},
  1205  	ErrAdminConfigNotificationTargetsFailed: {
  1206  		Code:           "XMinioAdminNotificationTargetsTestFailed",
  1207  		Description:    "Configuration update failed due an unsuccessful attempt to connect to one or more notification servers",
  1208  		HTTPStatusCode: http.StatusBadRequest,
  1209  	},
  1210  	ErrAdminProfilerNotEnabled: {
  1211  		Code:           "XMinioAdminProfilerNotEnabled",
  1212  		Description:    "Unable to perform the requested operation because profiling is not enabled",
  1213  		HTTPStatusCode: http.StatusBadRequest,
  1214  	},
  1215  	ErrAdminCredentialsMismatch: {
  1216  		Code:           "XMinioAdminCredentialsMismatch",
  1217  		Description:    "Credentials in config mismatch with server environment variables",
  1218  		HTTPStatusCode: http.StatusServiceUnavailable,
  1219  	},
  1220  	ErrAdminBucketQuotaExceeded: {
  1221  		Code:           "XMinioAdminBucketQuotaExceeded",
  1222  		Description:    "Bucket quota exceeded",
  1223  		HTTPStatusCode: http.StatusBadRequest,
  1224  	},
  1225  	ErrAdminNoSuchQuotaConfiguration: {
  1226  		Code:           "XMinioAdminNoSuchQuotaConfiguration",
  1227  		Description:    "The quota configuration does not exist",
  1228  		HTTPStatusCode: http.StatusNotFound,
  1229  	},
  1230  	ErrInsecureClientRequest: {
  1231  		Code:           "XMinioInsecureClientRequest",
  1232  		Description:    "Cannot respond to plain-text request from TLS-encrypted server",
  1233  		HTTPStatusCode: http.StatusBadRequest,
  1234  	},
  1235  	ErrOperationTimedOut: {
  1236  		Code:           "RequestTimeout",
  1237  		Description:    "A timeout occurred while trying to lock a resource, please reduce your request rate",
  1238  		HTTPStatusCode: http.StatusServiceUnavailable,
  1239  	},
  1240  	ErrClientDisconnected: {
  1241  		Code:           "ClientDisconnected",
  1242  		Description:    "Client disconnected before response was ready",
  1243  		HTTPStatusCode: 499, // No official code, use nginx value.
  1244  	},
  1245  	ErrOperationMaxedOut: {
  1246  		Code:           "SlowDown",
  1247  		Description:    "A timeout exceeded while waiting to proceed with the request, please reduce your request rate",
  1248  		HTTPStatusCode: http.StatusServiceUnavailable,
  1249  	},
  1250  	ErrUnsupportedMetadata: {
  1251  		Code:           "InvalidArgument",
  1252  		Description:    "Your metadata headers are not supported.",
  1253  		HTTPStatusCode: http.StatusBadRequest,
  1254  	},
  1255  	ErrObjectTampered: {
  1256  		Code:           "XMinioObjectTampered",
  1257  		Description:    errObjectTampered.Error(),
  1258  		HTTPStatusCode: http.StatusPartialContent,
  1259  	},
  1260  	ErrMaximumExpires: {
  1261  		Code:           "AuthorizationQueryParametersError",
  1262  		Description:    "X-Amz-Expires must be less than a week (in seconds); that is, the given X-Amz-Expires must be less than 604800 seconds",
  1263  		HTTPStatusCode: http.StatusBadRequest,
  1264  	},
  1265  
  1266  	// Generic Invalid-Request error. Should be used for response errors only for unlikely
  1267  	// corner case errors for which introducing new APIErrorCode is not worth it. LogIf()
  1268  	// should be used to log the error at the source of the error for debugging purposes.
  1269  	ErrInvalidRequest: {
  1270  		Code:           "InvalidRequest",
  1271  		Description:    "Invalid Request",
  1272  		HTTPStatusCode: http.StatusBadRequest,
  1273  	},
  1274  	ErrHealNotImplemented: {
  1275  		Code:           "XMinioHealNotImplemented",
  1276  		Description:    "This server does not implement heal functionality.",
  1277  		HTTPStatusCode: http.StatusBadRequest,
  1278  	},
  1279  	ErrHealNoSuchProcess: {
  1280  		Code:           "XMinioHealNoSuchProcess",
  1281  		Description:    "No such heal process is running on the server",
  1282  		HTTPStatusCode: http.StatusBadRequest,
  1283  	},
  1284  	ErrHealInvalidClientToken: {
  1285  		Code:           "XMinioHealInvalidClientToken",
  1286  		Description:    "Client token mismatch",
  1287  		HTTPStatusCode: http.StatusBadRequest,
  1288  	},
  1289  	ErrHealMissingBucket: {
  1290  		Code:           "XMinioHealMissingBucket",
  1291  		Description:    "A heal start request with a non-empty object-prefix parameter requires a bucket to be specified.",
  1292  		HTTPStatusCode: http.StatusBadRequest,
  1293  	},
  1294  	ErrHealAlreadyRunning: {
  1295  		Code:           "XMinioHealAlreadyRunning",
  1296  		Description:    "",
  1297  		HTTPStatusCode: http.StatusBadRequest,
  1298  	},
  1299  	ErrHealOverlappingPaths: {
  1300  		Code:           "XMinioHealOverlappingPaths",
  1301  		Description:    "",
  1302  		HTTPStatusCode: http.StatusBadRequest,
  1303  	},
  1304  	ErrBackendDown: {
  1305  		Code:           "XMinioBackendDown",
  1306  		Description:    "Object storage backend is unreachable",
  1307  		HTTPStatusCode: http.StatusServiceUnavailable,
  1308  	},
  1309  	ErrIncorrectContinuationToken: {
  1310  		Code:           "InvalidArgument",
  1311  		Description:    "The continuation token provided is incorrect",
  1312  		HTTPStatusCode: http.StatusBadRequest,
  1313  	},
  1314  	//S3 Select API Errors
  1315  	ErrEmptyRequestBody: {
  1316  		Code:           "EmptyRequestBody",
  1317  		Description:    "Request body cannot be empty.",
  1318  		HTTPStatusCode: http.StatusBadRequest,
  1319  	},
  1320  	ErrUnsupportedFunction: {
  1321  		Code:           "UnsupportedFunction",
  1322  		Description:    "Encountered an unsupported SQL function.",
  1323  		HTTPStatusCode: http.StatusBadRequest,
  1324  	},
  1325  	ErrInvalidDataSource: {
  1326  		Code:           "InvalidDataSource",
  1327  		Description:    "Invalid data source type. Only CSV and JSON are supported at this time.",
  1328  		HTTPStatusCode: http.StatusBadRequest,
  1329  	},
  1330  	ErrInvalidExpressionType: {
  1331  		Code:           "InvalidExpressionType",
  1332  		Description:    "The ExpressionType is invalid. Only SQL expressions are supported at this time.",
  1333  		HTTPStatusCode: http.StatusBadRequest,
  1334  	},
  1335  	ErrBusy: {
  1336  		Code:           "Busy",
  1337  		Description:    "The service is unavailable. Please retry.",
  1338  		HTTPStatusCode: http.StatusServiceUnavailable,
  1339  	},
  1340  	ErrUnauthorizedAccess: {
  1341  		Code:           "UnauthorizedAccess",
  1342  		Description:    "You are not authorized to perform this operation",
  1343  		HTTPStatusCode: http.StatusUnauthorized,
  1344  	},
  1345  	ErrExpressionTooLong: {
  1346  		Code:           "ExpressionTooLong",
  1347  		Description:    "The SQL expression is too long: The maximum byte-length for the SQL expression is 256 KB.",
  1348  		HTTPStatusCode: http.StatusBadRequest,
  1349  	},
  1350  	ErrIllegalSQLFunctionArgument: {
  1351  		Code:           "IllegalSqlFunctionArgument",
  1352  		Description:    "Illegal argument was used in the SQL function.",
  1353  		HTTPStatusCode: http.StatusBadRequest,
  1354  	},
  1355  	ErrInvalidKeyPath: {
  1356  		Code:           "InvalidKeyPath",
  1357  		Description:    "Key path in the SQL expression is invalid.",
  1358  		HTTPStatusCode: http.StatusBadRequest,
  1359  	},
  1360  	ErrInvalidCompressionFormat: {
  1361  		Code:           "InvalidCompressionFormat",
  1362  		Description:    "The file is not in a supported compression format. Only GZIP is supported at this time.",
  1363  		HTTPStatusCode: http.StatusBadRequest,
  1364  	},
  1365  	ErrInvalidFileHeaderInfo: {
  1366  		Code:           "InvalidFileHeaderInfo",
  1367  		Description:    "The FileHeaderInfo is invalid. Only NONE, USE, and IGNORE are supported.",
  1368  		HTTPStatusCode: http.StatusBadRequest,
  1369  	},
  1370  	ErrInvalidJSONType: {
  1371  		Code:           "InvalidJsonType",
  1372  		Description:    "The JsonType is invalid. Only DOCUMENT and LINES are supported at this time.",
  1373  		HTTPStatusCode: http.StatusBadRequest,
  1374  	},
  1375  	ErrInvalidQuoteFields: {
  1376  		Code:           "InvalidQuoteFields",
  1377  		Description:    "The QuoteFields is invalid. Only ALWAYS and ASNEEDED are supported.",
  1378  		HTTPStatusCode: http.StatusBadRequest,
  1379  	},
  1380  	ErrInvalidRequestParameter: {
  1381  		Code:           "InvalidRequestParameter",
  1382  		Description:    "The value of a parameter in SelectRequest element is invalid. Check the service API documentation and try again.",
  1383  		HTTPStatusCode: http.StatusBadRequest,
  1384  	},
  1385  	ErrInvalidDataType: {
  1386  		Code:           "InvalidDataType",
  1387  		Description:    "The SQL expression contains an invalid data type.",
  1388  		HTTPStatusCode: http.StatusBadRequest,
  1389  	},
  1390  	ErrInvalidTextEncoding: {
  1391  		Code:           "InvalidTextEncoding",
  1392  		Description:    "Invalid encoding type. Only UTF-8 encoding is supported at this time.",
  1393  		HTTPStatusCode: http.StatusBadRequest,
  1394  	},
  1395  	ErrInvalidTableAlias: {
  1396  		Code:           "InvalidTableAlias",
  1397  		Description:    "The SQL expression contains an invalid table alias.",
  1398  		HTTPStatusCode: http.StatusBadRequest,
  1399  	},
  1400  	ErrMissingRequiredParameter: {
  1401  		Code:           "MissingRequiredParameter",
  1402  		Description:    "The SelectRequest entity is missing a required parameter. Check the service documentation and try again.",
  1403  		HTTPStatusCode: http.StatusBadRequest,
  1404  	},
  1405  	ErrObjectSerializationConflict: {
  1406  		Code:           "ObjectSerializationConflict",
  1407  		Description:    "The SelectRequest entity can only contain one of CSV or JSON. Check the service documentation and try again.",
  1408  		HTTPStatusCode: http.StatusBadRequest,
  1409  	},
  1410  	ErrUnsupportedSQLOperation: {
  1411  		Code:           "UnsupportedSqlOperation",
  1412  		Description:    "Encountered an unsupported SQL operation.",
  1413  		HTTPStatusCode: http.StatusBadRequest,
  1414  	},
  1415  	ErrUnsupportedSQLStructure: {
  1416  		Code:           "UnsupportedSqlStructure",
  1417  		Description:    "Encountered an unsupported SQL structure. Check the SQL Reference.",
  1418  		HTTPStatusCode: http.StatusBadRequest,
  1419  	},
  1420  	ErrUnsupportedSyntax: {
  1421  		Code:           "UnsupportedSyntax",
  1422  		Description:    "Encountered invalid syntax.",
  1423  		HTTPStatusCode: http.StatusBadRequest,
  1424  	},
  1425  	ErrUnsupportedRangeHeader: {
  1426  		Code:           "UnsupportedRangeHeader",
  1427  		Description:    "Range header is not supported for this operation.",
  1428  		HTTPStatusCode: http.StatusBadRequest,
  1429  	},
  1430  	ErrLexerInvalidChar: {
  1431  		Code:           "LexerInvalidChar",
  1432  		Description:    "The SQL expression contains an invalid character.",
  1433  		HTTPStatusCode: http.StatusBadRequest,
  1434  	},
  1435  	ErrLexerInvalidOperator: {
  1436  		Code:           "LexerInvalidOperator",
  1437  		Description:    "The SQL expression contains an invalid literal.",
  1438  		HTTPStatusCode: http.StatusBadRequest,
  1439  	},
  1440  	ErrLexerInvalidLiteral: {
  1441  		Code:           "LexerInvalidLiteral",
  1442  		Description:    "The SQL expression contains an invalid operator.",
  1443  		HTTPStatusCode: http.StatusBadRequest,
  1444  	},
  1445  	ErrLexerInvalidIONLiteral: {
  1446  		Code:           "LexerInvalidIONLiteral",
  1447  		Description:    "The SQL expression contains an invalid operator.",
  1448  		HTTPStatusCode: http.StatusBadRequest,
  1449  	},
  1450  	ErrParseExpectedDatePart: {
  1451  		Code:           "ParseExpectedDatePart",
  1452  		Description:    "Did not find the expected date part in the SQL expression.",
  1453  		HTTPStatusCode: http.StatusBadRequest,
  1454  	},
  1455  	ErrParseExpectedKeyword: {
  1456  		Code:           "ParseExpectedKeyword",
  1457  		Description:    "Did not find the expected keyword in the SQL expression.",
  1458  		HTTPStatusCode: http.StatusBadRequest,
  1459  	},
  1460  	ErrParseExpectedTokenType: {
  1461  		Code:           "ParseExpectedTokenType",
  1462  		Description:    "Did not find the expected token in the SQL expression.",
  1463  		HTTPStatusCode: http.StatusBadRequest,
  1464  	},
  1465  	ErrParseExpected2TokenTypes: {
  1466  		Code:           "ParseExpected2TokenTypes",
  1467  		Description:    "Did not find the expected token in the SQL expression.",
  1468  		HTTPStatusCode: http.StatusBadRequest,
  1469  	},
  1470  	ErrParseExpectedNumber: {
  1471  		Code:           "ParseExpectedNumber",
  1472  		Description:    "Did not find the expected number in the SQL expression.",
  1473  		HTTPStatusCode: http.StatusBadRequest,
  1474  	},
  1475  	ErrParseExpectedRightParenBuiltinFunctionCall: {
  1476  		Code:           "ParseExpectedRightParenBuiltinFunctionCall",
  1477  		Description:    "Did not find the expected right parenthesis character in the SQL expression.",
  1478  		HTTPStatusCode: http.StatusBadRequest,
  1479  	},
  1480  	ErrParseExpectedTypeName: {
  1481  		Code:           "ParseExpectedTypeName",
  1482  		Description:    "Did not find the expected type name in the SQL expression.",
  1483  		HTTPStatusCode: http.StatusBadRequest,
  1484  	},
  1485  	ErrParseExpectedWhenClause: {
  1486  		Code:           "ParseExpectedWhenClause",
  1487  		Description:    "Did not find the expected WHEN clause in the SQL expression. CASE is not supported.",
  1488  		HTTPStatusCode: http.StatusBadRequest,
  1489  	},
  1490  	ErrParseUnsupportedToken: {
  1491  		Code:           "ParseUnsupportedToken",
  1492  		Description:    "The SQL expression contains an unsupported token.",
  1493  		HTTPStatusCode: http.StatusBadRequest,
  1494  	},
  1495  	ErrParseUnsupportedLiteralsGroupBy: {
  1496  		Code:           "ParseUnsupportedLiteralsGroupBy",
  1497  		Description:    "The SQL expression contains an unsupported use of GROUP BY.",
  1498  		HTTPStatusCode: http.StatusBadRequest,
  1499  	},
  1500  	ErrParseExpectedMember: {
  1501  		Code:           "ParseExpectedMember",
  1502  		Description:    "The SQL expression contains an unsupported use of MEMBER.",
  1503  		HTTPStatusCode: http.StatusBadRequest,
  1504  	},
  1505  	ErrParseUnsupportedSelect: {
  1506  		Code:           "ParseUnsupportedSelect",
  1507  		Description:    "The SQL expression contains an unsupported use of SELECT.",
  1508  		HTTPStatusCode: http.StatusBadRequest,
  1509  	},
  1510  	ErrParseUnsupportedCase: {
  1511  		Code:           "ParseUnsupportedCase",
  1512  		Description:    "The SQL expression contains an unsupported use of CASE.",
  1513  		HTTPStatusCode: http.StatusBadRequest,
  1514  	},
  1515  	ErrParseUnsupportedCaseClause: {
  1516  		Code:           "ParseUnsupportedCaseClause",
  1517  		Description:    "The SQL expression contains an unsupported use of CASE.",
  1518  		HTTPStatusCode: http.StatusBadRequest,
  1519  	},
  1520  	ErrParseUnsupportedAlias: {
  1521  		Code:           "ParseUnsupportedAlias",
  1522  		Description:    "The SQL expression contains an unsupported use of ALIAS.",
  1523  		HTTPStatusCode: http.StatusBadRequest,
  1524  	},
  1525  	ErrParseUnsupportedSyntax: {
  1526  		Code:           "ParseUnsupportedSyntax",
  1527  		Description:    "The SQL expression contains unsupported syntax.",
  1528  		HTTPStatusCode: http.StatusBadRequest,
  1529  	},
  1530  	ErrParseUnknownOperator: {
  1531  		Code:           "ParseUnknownOperator",
  1532  		Description:    "The SQL expression contains an invalid operator.",
  1533  		HTTPStatusCode: http.StatusBadRequest,
  1534  	},
  1535  	ErrParseMissingIdentAfterAt: {
  1536  		Code:           "ParseMissingIdentAfterAt",
  1537  		Description:    "Did not find the expected identifier after the @ symbol in the SQL expression.",
  1538  		HTTPStatusCode: http.StatusBadRequest,
  1539  	},
  1540  	ErrParseUnexpectedOperator: {
  1541  		Code:           "ParseUnexpectedOperator",
  1542  		Description:    "The SQL expression contains an unexpected operator.",
  1543  		HTTPStatusCode: http.StatusBadRequest,
  1544  	},
  1545  	ErrParseUnexpectedTerm: {
  1546  		Code:           "ParseUnexpectedTerm",
  1547  		Description:    "The SQL expression contains an unexpected term.",
  1548  		HTTPStatusCode: http.StatusBadRequest,
  1549  	},
  1550  	ErrParseUnexpectedToken: {
  1551  		Code:           "ParseUnexpectedToken",
  1552  		Description:    "The SQL expression contains an unexpected token.",
  1553  		HTTPStatusCode: http.StatusBadRequest,
  1554  	},
  1555  	ErrParseUnexpectedKeyword: {
  1556  		Code:           "ParseUnexpectedKeyword",
  1557  		Description:    "The SQL expression contains an unexpected keyword.",
  1558  		HTTPStatusCode: http.StatusBadRequest,
  1559  	},
  1560  	ErrParseExpectedExpression: {
  1561  		Code:           "ParseExpectedExpression",
  1562  		Description:    "Did not find the expected SQL expression.",
  1563  		HTTPStatusCode: http.StatusBadRequest,
  1564  	},
  1565  	ErrParseExpectedLeftParenAfterCast: {
  1566  		Code:           "ParseExpectedLeftParenAfterCast",
  1567  		Description:    "Did not find expected the left parenthesis in the SQL expression.",
  1568  		HTTPStatusCode: http.StatusBadRequest,
  1569  	},
  1570  	ErrParseExpectedLeftParenValueConstructor: {
  1571  		Code:           "ParseExpectedLeftParenValueConstructor",
  1572  		Description:    "Did not find expected the left parenthesis in the SQL expression.",
  1573  		HTTPStatusCode: http.StatusBadRequest,
  1574  	},
  1575  	ErrParseExpectedLeftParenBuiltinFunctionCall: {
  1576  		Code:           "ParseExpectedLeftParenBuiltinFunctionCall",
  1577  		Description:    "Did not find the expected left parenthesis in the SQL expression.",
  1578  		HTTPStatusCode: http.StatusBadRequest,
  1579  	},
  1580  	ErrParseExpectedArgumentDelimiter: {
  1581  		Code:           "ParseExpectedArgumentDelimiter",
  1582  		Description:    "Did not find the expected argument delimiter in the SQL expression.",
  1583  		HTTPStatusCode: http.StatusBadRequest,
  1584  	},
  1585  	ErrParseCastArity: {
  1586  		Code:           "ParseCastArity",
  1587  		Description:    "The SQL expression CAST has incorrect arity.",
  1588  		HTTPStatusCode: http.StatusBadRequest,
  1589  	},
  1590  	ErrParseInvalidTypeParam: {
  1591  		Code:           "ParseInvalidTypeParam",
  1592  		Description:    "The SQL expression contains an invalid parameter value.",
  1593  		HTTPStatusCode: http.StatusBadRequest,
  1594  	},
  1595  	ErrParseEmptySelect: {
  1596  		Code:           "ParseEmptySelect",
  1597  		Description:    "The SQL expression contains an empty SELECT.",
  1598  		HTTPStatusCode: http.StatusBadRequest,
  1599  	},
  1600  	ErrParseSelectMissingFrom: {
  1601  		Code:           "ParseSelectMissingFrom",
  1602  		Description:    "GROUP is not supported in the SQL expression.",
  1603  		HTTPStatusCode: http.StatusBadRequest,
  1604  	},
  1605  	ErrParseExpectedIdentForGroupName: {
  1606  		Code:           "ParseExpectedIdentForGroupName",
  1607  		Description:    "GROUP is not supported in the SQL expression.",
  1608  		HTTPStatusCode: http.StatusBadRequest,
  1609  	},
  1610  	ErrParseExpectedIdentForAlias: {
  1611  		Code:           "ParseExpectedIdentForAlias",
  1612  		Description:    "Did not find the expected identifier for the alias in the SQL expression.",
  1613  		HTTPStatusCode: http.StatusBadRequest,
  1614  	},
  1615  	ErrParseUnsupportedCallWithStar: {
  1616  		Code:           "ParseUnsupportedCallWithStar",
  1617  		Description:    "Only COUNT with (*) as a parameter is supported in the SQL expression.",
  1618  		HTTPStatusCode: http.StatusBadRequest,
  1619  	},
  1620  	ErrParseNonUnaryAgregateFunctionCall: {
  1621  		Code:           "ParseNonUnaryAgregateFunctionCall",
  1622  		Description:    "Only one argument is supported for aggregate functions in the SQL expression.",
  1623  		HTTPStatusCode: http.StatusBadRequest,
  1624  	},
  1625  	ErrParseMalformedJoin: {
  1626  		Code:           "ParseMalformedJoin",
  1627  		Description:    "JOIN is not supported in the SQL expression.",
  1628  		HTTPStatusCode: http.StatusBadRequest,
  1629  	},
  1630  	ErrParseExpectedIdentForAt: {
  1631  		Code:           "ParseExpectedIdentForAt",
  1632  		Description:    "Did not find the expected identifier for AT name in the SQL expression.",
  1633  		HTTPStatusCode: http.StatusBadRequest,
  1634  	},
  1635  	ErrParseAsteriskIsNotAloneInSelectList: {
  1636  		Code:           "ParseAsteriskIsNotAloneInSelectList",
  1637  		Description:    "Other expressions are not allowed in the SELECT list when '*' is used without dot notation in the SQL expression.",
  1638  		HTTPStatusCode: http.StatusBadRequest,
  1639  	},
  1640  	ErrParseCannotMixSqbAndWildcardInSelectList: {
  1641  		Code:           "ParseCannotMixSqbAndWildcardInSelectList",
  1642  		Description:    "Cannot mix [] and * in the same expression in a SELECT list in SQL expression.",
  1643  		HTTPStatusCode: http.StatusBadRequest,
  1644  	},
  1645  	ErrParseInvalidContextForWildcardInSelectList: {
  1646  		Code:           "ParseInvalidContextForWildcardInSelectList",
  1647  		Description:    "Invalid use of * in SELECT list in the SQL expression.",
  1648  		HTTPStatusCode: http.StatusBadRequest,
  1649  	},
  1650  	ErrIncorrectSQLFunctionArgumentType: {
  1651  		Code:           "IncorrectSqlFunctionArgumentType",
  1652  		Description:    "Incorrect type of arguments in function call in the SQL expression.",
  1653  		HTTPStatusCode: http.StatusBadRequest,
  1654  	},
  1655  	ErrValueParseFailure: {
  1656  		Code:           "ValueParseFailure",
  1657  		Description:    "Time stamp parse failure in the SQL expression.",
  1658  		HTTPStatusCode: http.StatusBadRequest,
  1659  	},
  1660  	ErrEvaluatorInvalidArguments: {
  1661  		Code:           "EvaluatorInvalidArguments",
  1662  		Description:    "Incorrect number of arguments in the function call in the SQL expression.",
  1663  		HTTPStatusCode: http.StatusBadRequest,
  1664  	},
  1665  	ErrIntegerOverflow: {
  1666  		Code:           "IntegerOverflow",
  1667  		Description:    "Int overflow or underflow in the SQL expression.",
  1668  		HTTPStatusCode: http.StatusBadRequest,
  1669  	},
  1670  	ErrLikeInvalidInputs: {
  1671  		Code:           "LikeInvalidInputs",
  1672  		Description:    "Invalid argument given to the LIKE clause in the SQL expression.",
  1673  		HTTPStatusCode: http.StatusBadRequest,
  1674  	},
  1675  	ErrCastFailed: {
  1676  		Code:           "CastFailed",
  1677  		Description:    "Attempt to convert from one data type to another using CAST failed in the SQL expression.",
  1678  		HTTPStatusCode: http.StatusBadRequest,
  1679  	},
  1680  	ErrInvalidCast: {
  1681  		Code:           "InvalidCast",
  1682  		Description:    "Attempt to convert from one data type to another using CAST failed in the SQL expression.",
  1683  		HTTPStatusCode: http.StatusBadRequest,
  1684  	},
  1685  	ErrEvaluatorInvalidTimestampFormatPattern: {
  1686  		Code:           "EvaluatorInvalidTimestampFormatPattern",
  1687  		Description:    "Time stamp format pattern requires additional fields in the SQL expression.",
  1688  		HTTPStatusCode: http.StatusBadRequest,
  1689  	},
  1690  	ErrEvaluatorInvalidTimestampFormatPatternSymbolForParsing: {
  1691  		Code:           "EvaluatorInvalidTimestampFormatPatternSymbolForParsing",
  1692  		Description:    "Time stamp format pattern contains a valid format symbol that cannot be applied to time stamp parsing in the SQL expression.",
  1693  		HTTPStatusCode: http.StatusBadRequest,
  1694  	},
  1695  	ErrEvaluatorTimestampFormatPatternDuplicateFields: {
  1696  		Code:           "EvaluatorTimestampFormatPatternDuplicateFields",
  1697  		Description:    "Time stamp format pattern contains multiple format specifiers representing the time stamp field in the SQL expression.",
  1698  		HTTPStatusCode: http.StatusBadRequest,
  1699  	},
  1700  	ErrEvaluatorTimestampFormatPatternHourClockAmPmMismatch: {
  1701  		Code:           "EvaluatorUnterminatedTimestampFormatPatternToken",
  1702  		Description:    "Time stamp format pattern contains unterminated token in the SQL expression.",
  1703  		HTTPStatusCode: http.StatusBadRequest,
  1704  	},
  1705  	ErrEvaluatorUnterminatedTimestampFormatPatternToken: {
  1706  		Code:           "EvaluatorInvalidTimestampFormatPatternToken",
  1707  		Description:    "Time stamp format pattern contains an invalid token in the SQL expression.",
  1708  		HTTPStatusCode: http.StatusBadRequest,
  1709  	},
  1710  	ErrEvaluatorInvalidTimestampFormatPatternToken: {
  1711  		Code:           "EvaluatorInvalidTimestampFormatPatternToken",
  1712  		Description:    "Time stamp format pattern contains an invalid token in the SQL expression.",
  1713  		HTTPStatusCode: http.StatusBadRequest,
  1714  	},
  1715  	ErrEvaluatorInvalidTimestampFormatPatternSymbol: {
  1716  		Code:           "EvaluatorInvalidTimestampFormatPatternSymbol",
  1717  		Description:    "Time stamp format pattern contains an invalid symbol in the SQL expression.",
  1718  		HTTPStatusCode: http.StatusBadRequest,
  1719  	},
  1720  	ErrEvaluatorBindingDoesNotExist: {
  1721  		Code:           "ErrEvaluatorBindingDoesNotExist",
  1722  		Description:    "A column name or a path provided does not exist in the SQL expression",
  1723  		HTTPStatusCode: http.StatusBadRequest,
  1724  	},
  1725  	ErrMissingHeaders: {
  1726  		Code:           "MissingHeaders",
  1727  		Description:    "Some headers in the query are missing from the file. Check the file and try again.",
  1728  		HTTPStatusCode: http.StatusBadRequest,
  1729  	},
  1730  	ErrInvalidColumnIndex: {
  1731  		Code:           "InvalidColumnIndex",
  1732  		Description:    "The column index is invalid. Please check the service documentation and try again.",
  1733  		HTTPStatusCode: http.StatusBadRequest,
  1734  	},
  1735  	ErrInvalidDecompressedSize: {
  1736  		Code:           "XMinioInvalidDecompressedSize",
  1737  		Description:    "The data provided is unfit for decompression",
  1738  		HTTPStatusCode: http.StatusBadRequest,
  1739  	},
  1740  	ErrAddUserInvalidArgument: {
  1741  		Code:           "XMinioInvalidIAMCredentials",
  1742  		Description:    "User is not allowed to be same as admin access key",
  1743  		HTTPStatusCode: http.StatusForbidden,
  1744  	},
  1745  	ErrAdminAccountNotEligible: {
  1746  		Code:           "XMinioInvalidIAMCredentials",
  1747  		Description:    "The administrator key is not eligible for this operation",
  1748  		HTTPStatusCode: http.StatusForbidden,
  1749  	},
  1750  	ErrAccountNotEligible: {
  1751  		Code:           "XMinioInvalidIAMCredentials",
  1752  		Description:    "The account key is not eligible for this operation",
  1753  		HTTPStatusCode: http.StatusForbidden,
  1754  	},
  1755  	ErrAdminServiceAccountNotFound: {
  1756  		Code:           "XMinioInvalidIAMCredentials",
  1757  		Description:    "The specified service account is not found",
  1758  		HTTPStatusCode: http.StatusNotFound,
  1759  	},
  1760  	ErrPostPolicyConditionInvalidFormat: {
  1761  		Code:           "PostPolicyInvalidKeyName",
  1762  		Description:    "Invalid according to Policy: Policy Condition failed",
  1763  		HTTPStatusCode: http.StatusForbidden,
  1764  	},
  1765  	// Add your error structure here.
  1766  }
  1767  
  1768  // toAPIErrorCode - Converts embedded errors. Convenience
  1769  // function written to handle all cases where we have known types of
  1770  // errors returned by underlying layers.
  1771  func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) {
  1772  	if err == nil {
  1773  		return ErrNone
  1774  	}
  1775  
  1776  	// Only return ErrClientDisconnected if the provided context is actually canceled.
  1777  	// This way downstream context.Canceled will still report ErrOperationTimedOut
  1778  	select {
  1779  	case <-ctx.Done():
  1780  		if ctx.Err() == context.Canceled {
  1781  			return ErrClientDisconnected
  1782  		}
  1783  	default:
  1784  	}
  1785  
  1786  	switch err {
  1787  	case errInvalidArgument:
  1788  		apiErr = ErrAdminInvalidArgument
  1789  	case errNoSuchUser:
  1790  		apiErr = ErrAdminNoSuchUser
  1791  	case errNoSuchServiceAccount:
  1792  		apiErr = ErrAdminServiceAccountNotFound
  1793  	case errNoSuchGroup:
  1794  		apiErr = ErrAdminNoSuchGroup
  1795  	case errGroupNotEmpty:
  1796  		apiErr = ErrAdminGroupNotEmpty
  1797  	case errNoSuchPolicy:
  1798  		apiErr = ErrAdminNoSuchPolicy
  1799  	case errSignatureMismatch:
  1800  		apiErr = ErrSignatureDoesNotMatch
  1801  	case errInvalidRange:
  1802  		apiErr = ErrInvalidRange
  1803  	case errDataTooLarge:
  1804  		apiErr = ErrEntityTooLarge
  1805  	case errDataTooSmall:
  1806  		apiErr = ErrEntityTooSmall
  1807  	case errAuthentication:
  1808  		apiErr = ErrAccessDenied
  1809  	case auth.ErrInvalidAccessKeyLength:
  1810  		apiErr = ErrAdminInvalidAccessKey
  1811  	case auth.ErrInvalidSecretKeyLength:
  1812  		apiErr = ErrAdminInvalidSecretKey
  1813  	// SSE errors
  1814  	case errInvalidEncryptionParameters:
  1815  		apiErr = ErrInvalidEncryptionParameters
  1816  	case crypto.ErrInvalidEncryptionMethod:
  1817  		apiErr = ErrInvalidEncryptionMethod
  1818  	case crypto.ErrInvalidCustomerAlgorithm:
  1819  		apiErr = ErrInvalidSSECustomerAlgorithm
  1820  	case crypto.ErrMissingCustomerKey:
  1821  		apiErr = ErrMissingSSECustomerKey
  1822  	case crypto.ErrMissingCustomerKeyMD5:
  1823  		apiErr = ErrMissingSSECustomerKeyMD5
  1824  	case crypto.ErrCustomerKeyMD5Mismatch:
  1825  		apiErr = ErrSSECustomerKeyMD5Mismatch
  1826  	case errObjectTampered:
  1827  		apiErr = ErrObjectTampered
  1828  	case errEncryptedObject:
  1829  		apiErr = ErrSSEEncryptedObject
  1830  	case errInvalidSSEParameters:
  1831  		apiErr = ErrInvalidSSECustomerParameters
  1832  	case crypto.ErrInvalidCustomerKey, crypto.ErrSecretKeyMismatch:
  1833  		apiErr = ErrAccessDenied // no access without correct key
  1834  	case crypto.ErrIncompatibleEncryptionMethod:
  1835  		apiErr = ErrIncompatibleEncryptionMethod
  1836  	case errKMSNotConfigured:
  1837  		apiErr = ErrKMSNotConfigured
  1838  	case context.Canceled, context.DeadlineExceeded:
  1839  		apiErr = ErrOperationTimedOut
  1840  	case errDiskNotFound:
  1841  		apiErr = ErrSlowDown
  1842  	case objectlock.ErrInvalidRetentionDate:
  1843  		apiErr = ErrInvalidRetentionDate
  1844  	case objectlock.ErrPastObjectLockRetainDate:
  1845  		apiErr = ErrPastObjectLockRetainDate
  1846  	case objectlock.ErrUnknownWORMModeDirective:
  1847  		apiErr = ErrUnknownWORMModeDirective
  1848  	case objectlock.ErrObjectLockInvalidHeaders:
  1849  		apiErr = ErrObjectLockInvalidHeaders
  1850  	case objectlock.ErrMalformedXML:
  1851  		apiErr = ErrMalformedXML
  1852  	}
  1853  
  1854  	// Compression errors
  1855  	switch err {
  1856  	case errInvalidDecompressedSize:
  1857  		apiErr = ErrInvalidDecompressedSize
  1858  	}
  1859  
  1860  	if apiErr != ErrNone {
  1861  		// If there was a match in the above switch case.
  1862  		return apiErr
  1863  	}
  1864  
  1865  	switch err.(type) {
  1866  	case StorageFull:
  1867  		apiErr = ErrStorageFull
  1868  	case hash.BadDigest:
  1869  		apiErr = ErrBadDigest
  1870  	case AllAccessDisabled:
  1871  		apiErr = ErrAllAccessDisabled
  1872  	case IncompleteBody:
  1873  		apiErr = ErrIncompleteBody
  1874  	case ObjectExistsAsDirectory:
  1875  		apiErr = ErrObjectExistsAsDirectory
  1876  	case PrefixAccessDenied:
  1877  		apiErr = ErrAccessDenied
  1878  	case ParentIsObject:
  1879  		apiErr = ErrParentIsObject
  1880  	case BucketNameInvalid:
  1881  		apiErr = ErrInvalidBucketName
  1882  	case BucketNotFound:
  1883  		apiErr = ErrNoSuchBucket
  1884  	case BucketAlreadyOwnedByYou:
  1885  		apiErr = ErrBucketAlreadyOwnedByYou
  1886  	case BucketNotEmpty:
  1887  		apiErr = ErrBucketNotEmpty
  1888  	case BucketAlreadyExists:
  1889  		apiErr = ErrBucketAlreadyExists
  1890  	case BucketExists:
  1891  		apiErr = ErrBucketAlreadyOwnedByYou
  1892  	case ObjectNotFound:
  1893  		apiErr = ErrNoSuchKey
  1894  	case MethodNotAllowed:
  1895  		apiErr = ErrMethodNotAllowed
  1896  	case InvalidVersionID:
  1897  		apiErr = ErrInvalidVersionID
  1898  	case VersionNotFound:
  1899  		apiErr = ErrNoSuchVersion
  1900  	case ObjectAlreadyExists:
  1901  		apiErr = ErrMethodNotAllowed
  1902  	case ObjectNameInvalid:
  1903  		apiErr = ErrInvalidObjectName
  1904  	case ObjectNamePrefixAsSlash:
  1905  		apiErr = ErrInvalidObjectNamePrefixSlash
  1906  	case InvalidUploadID:
  1907  		apiErr = ErrNoSuchUpload
  1908  	case InvalidPart:
  1909  		apiErr = ErrInvalidPart
  1910  	case InsufficientWriteQuorum:
  1911  		apiErr = ErrSlowDown
  1912  	case InsufficientReadQuorum:
  1913  		apiErr = ErrSlowDown
  1914  	case InvalidMarkerPrefixCombination:
  1915  		apiErr = ErrNotImplemented
  1916  	case InvalidUploadIDKeyCombination:
  1917  		apiErr = ErrNotImplemented
  1918  	case MalformedUploadID:
  1919  		apiErr = ErrNoSuchUpload
  1920  	case PartTooSmall:
  1921  		apiErr = ErrEntityTooSmall
  1922  	case SignatureDoesNotMatch:
  1923  		apiErr = ErrSignatureDoesNotMatch
  1924  	case hash.SHA256Mismatch:
  1925  		apiErr = ErrContentSHA256Mismatch
  1926  	case ObjectTooLarge:
  1927  		apiErr = ErrEntityTooLarge
  1928  	case ObjectTooSmall:
  1929  		apiErr = ErrEntityTooSmall
  1930  	case NotImplemented:
  1931  		apiErr = ErrNotImplemented
  1932  	case PartTooBig:
  1933  		apiErr = ErrEntityTooLarge
  1934  	case UnsupportedMetadata:
  1935  		apiErr = ErrUnsupportedMetadata
  1936  	case BucketPolicyNotFound:
  1937  		apiErr = ErrNoSuchBucketPolicy
  1938  	case BucketLifecycleNotFound:
  1939  		apiErr = ErrNoSuchLifecycleConfiguration
  1940  	case BucketSSEConfigNotFound:
  1941  		apiErr = ErrNoSuchBucketSSEConfig
  1942  	case BucketTaggingNotFound:
  1943  		apiErr = ErrBucketTaggingNotFound
  1944  	case BucketObjectLockConfigNotFound:
  1945  		apiErr = ErrObjectLockConfigurationNotFound
  1946  	case BucketQuotaConfigNotFound:
  1947  		apiErr = ErrAdminNoSuchQuotaConfiguration
  1948  	case BucketReplicationConfigNotFound:
  1949  		apiErr = ErrReplicationConfigurationNotFoundError
  1950  	case BucketRemoteDestinationNotFound:
  1951  		apiErr = ErrRemoteDestinationNotFoundError
  1952  	case BucketReplicationDestinationMissingLock:
  1953  		apiErr = ErrReplicationDestinationMissingLock
  1954  	case BucketRemoteTargetNotFound:
  1955  		apiErr = ErrRemoteTargetNotFoundError
  1956  	case BucketRemoteConnectionErr:
  1957  		apiErr = ErrReplicationRemoteConnectionError
  1958  	case BucketRemoteAlreadyExists:
  1959  		apiErr = ErrBucketRemoteAlreadyExists
  1960  	case BucketRemoteLabelInUse:
  1961  		apiErr = ErrBucketRemoteLabelInUse
  1962  	case BucketRemoteArnTypeInvalid:
  1963  		apiErr = ErrBucketRemoteArnTypeInvalid
  1964  	case BucketRemoteArnInvalid:
  1965  		apiErr = ErrBucketRemoteArnInvalid
  1966  	case BucketRemoteRemoveDisallowed:
  1967  		apiErr = ErrBucketRemoteRemoveDisallowed
  1968  	case BucketRemoteTargetNotVersioned:
  1969  		apiErr = ErrRemoteTargetNotVersionedError
  1970  	case BucketReplicationSourceNotVersioned:
  1971  		apiErr = ErrReplicationSourceNotVersionedError
  1972  	case BucketQuotaExceeded:
  1973  		apiErr = ErrAdminBucketQuotaExceeded
  1974  	case *event.ErrInvalidEventName:
  1975  		apiErr = ErrEventNotification
  1976  	case *event.ErrInvalidARN:
  1977  		apiErr = ErrARNNotification
  1978  	case *event.ErrARNNotFound:
  1979  		apiErr = ErrARNNotification
  1980  	case *event.ErrUnknownRegion:
  1981  		apiErr = ErrRegionNotification
  1982  	case *event.ErrInvalidFilterName:
  1983  		apiErr = ErrFilterNameInvalid
  1984  	case *event.ErrFilterNamePrefix:
  1985  		apiErr = ErrFilterNamePrefix
  1986  	case *event.ErrFilterNameSuffix:
  1987  		apiErr = ErrFilterNameSuffix
  1988  	case *event.ErrInvalidFilterValue:
  1989  		apiErr = ErrFilterValueInvalid
  1990  	case *event.ErrDuplicateEventName:
  1991  		apiErr = ErrOverlappingConfigs
  1992  	case *event.ErrDuplicateQueueConfiguration:
  1993  		apiErr = ErrOverlappingFilterNotification
  1994  	case *event.ErrUnsupportedConfiguration:
  1995  		apiErr = ErrUnsupportedNotification
  1996  	case OperationTimedOut:
  1997  		apiErr = ErrOperationTimedOut
  1998  	case BackendDown:
  1999  		apiErr = ErrBackendDown
  2000  	case ObjectNameTooLong:
  2001  		apiErr = ErrKeyTooLongError
  2002  	default:
  2003  		var ie, iw int
  2004  		// This work-around is to handle the issue golang/go#30648
  2005  		if _, ferr := fmt.Fscanf(strings.NewReader(err.Error()),
  2006  			"request declared a Content-Length of %d but only wrote %d bytes",
  2007  			&ie, &iw); ferr != nil {
  2008  			apiErr = ErrInternalError
  2009  			// Make sure to log the errors which we cannot translate
  2010  			// to a meaningful S3 API errors. This is added to aid in
  2011  			// debugging unexpected/unhandled errors.
  2012  			logger.LogIf(ctx, err)
  2013  		} else if ie > iw {
  2014  			apiErr = ErrIncompleteBody
  2015  		} else {
  2016  			apiErr = ErrInternalError
  2017  			// Make sure to log the errors which we cannot translate
  2018  			// to a meaningful S3 API errors. This is added to aid in
  2019  			// debugging unexpected/unhandled errors.
  2020  			logger.LogIf(ctx, err)
  2021  		}
  2022  	}
  2023  
  2024  	return apiErr
  2025  }
  2026  
  2027  var noError = APIError{}
  2028  
  2029  // ToAPIError - Converts embedded errors. Convenience
  2030  // function written to handle all cases where we have known types of
  2031  // errors returned by underlying layers.
  2032  func ToAPIError(ctx context.Context, err error) APIError {
  2033  	if err == nil {
  2034  		return noError
  2035  	}
  2036  
  2037  	var apiErr = errorCodes.ToAPIErr(toAPIErrorCode(ctx, err))
  2038  
  2039  	if apiErr.Code == "NotImplemented" {
  2040  		switch e := err.(type) {
  2041  		case NotImplemented:
  2042  			desc := e.Error()
  2043  			if desc == "" {
  2044  				desc = apiErr.Description
  2045  			}
  2046  			apiErr = APIError{
  2047  				Code:           apiErr.Code,
  2048  				Description:    desc,
  2049  				HTTPStatusCode: apiErr.HTTPStatusCode,
  2050  			}
  2051  			return apiErr
  2052  		}
  2053  	}
  2054  
  2055  	if apiErr.Code == "InternalError" {
  2056  		// If we see an internal error try to interpret
  2057  		// any underlying errors if possible depending on
  2058  		// their internal error types. This code is only
  2059  		// useful with gateway implementations.
  2060  		switch e := err.(type) {
  2061  		case InvalidArgument:
  2062  			apiErr = APIError{
  2063  				Code:           "InvalidArgument",
  2064  				Description:    e.Error(),
  2065  				HTTPStatusCode: errorCodes[ErrInvalidRequest].HTTPStatusCode,
  2066  			}
  2067  		case *xml.SyntaxError:
  2068  			apiErr = APIError{
  2069  				Code: "MalformedXML",
  2070  				Description: fmt.Sprintf("%s (%s)", errorCodes[ErrMalformedXML].Description,
  2071  					e.Error()),
  2072  				HTTPStatusCode: errorCodes[ErrMalformedXML].HTTPStatusCode,
  2073  			}
  2074  		case url.EscapeError:
  2075  			apiErr = APIError{
  2076  				Code: "XMinioInvalidObjectName",
  2077  				Description: fmt.Sprintf("%s (%s)", errorCodes[ErrInvalidObjectName].Description,
  2078  					e.Error()),
  2079  				HTTPStatusCode: http.StatusBadRequest,
  2080  			}
  2081  		case versioning.Error:
  2082  			apiErr = APIError{
  2083  				Code:           "IllegalVersioningConfigurationException",
  2084  				Description:    fmt.Sprintf("Versioning configuration specified in the request is invalid. (%s)", e.Error()),
  2085  				HTTPStatusCode: http.StatusBadRequest,
  2086  			}
  2087  		case lifecycle.Error:
  2088  			apiErr = APIError{
  2089  				Code:           "InvalidRequest",
  2090  				Description:    e.Error(),
  2091  				HTTPStatusCode: http.StatusBadRequest,
  2092  			}
  2093  		case replication.Error:
  2094  			apiErr = APIError{
  2095  				Code:           "MalformedXML",
  2096  				Description:    e.Error(),
  2097  				HTTPStatusCode: http.StatusBadRequest,
  2098  			}
  2099  		case tags.Error:
  2100  			apiErr = APIError{
  2101  				Code:           e.Code(),
  2102  				Description:    e.Error(),
  2103  				HTTPStatusCode: http.StatusBadRequest,
  2104  			}
  2105  		case policy.Error:
  2106  			apiErr = APIError{
  2107  				Code:           "MalformedPolicy",
  2108  				Description:    e.Error(),
  2109  				HTTPStatusCode: http.StatusBadRequest,
  2110  			}
  2111  		case crypto.Error:
  2112  			apiErr = APIError{
  2113  				Code:           "XMinIOEncryptionError",
  2114  				Description:    e.Error(),
  2115  				HTTPStatusCode: http.StatusBadRequest,
  2116  			}
  2117  		case minio.ErrorResponse:
  2118  			apiErr = APIError{
  2119  				Code:           e.Code,
  2120  				Description:    e.Message,
  2121  				HTTPStatusCode: e.StatusCode,
  2122  			}
  2123  			if GlobalIsGateway && strings.Contains(e.Message, "KMS is not configured") {
  2124  				apiErr = APIError{
  2125  					Code:           "NotImplemented",
  2126  					Description:    e.Message,
  2127  					HTTPStatusCode: http.StatusNotImplemented,
  2128  				}
  2129  			}
  2130  		case *googleapi.Error:
  2131  			apiErr = APIError{
  2132  				Code:           "XGCSInternalError",
  2133  				Description:    e.Message,
  2134  				HTTPStatusCode: e.Code,
  2135  			}
  2136  			// GCS may send multiple errors, just pick the first one
  2137  			// since S3 only sends one Error XML response.
  2138  			if len(e.Errors) >= 1 {
  2139  				apiErr.Code = e.Errors[0].Reason
  2140  
  2141  			}
  2142  		case azblob.StorageError:
  2143  			apiErr = APIError{
  2144  				Code:           string(e.ServiceCode()),
  2145  				Description:    e.Error(),
  2146  				HTTPStatusCode: e.Response().StatusCode,
  2147  			}
  2148  			// Add more Gateway SDKs here if any in future.
  2149  		default:
  2150  			apiErr = APIError{
  2151  				Code:           apiErr.Code,
  2152  				Description:    fmt.Sprintf("%s: cause(%v)", apiErr.Description, err),
  2153  				HTTPStatusCode: apiErr.HTTPStatusCode,
  2154  			}
  2155  		}
  2156  	}
  2157  
  2158  	return apiErr
  2159  }
  2160  
  2161  // GetAPIError provides API Error for input API error code.
  2162  func GetAPIError(code APIErrorCode) APIError {
  2163  	if apiErr, ok := errorCodes[code]; ok {
  2164  		return apiErr
  2165  	}
  2166  	return errorCodes.ToAPIErr(ErrInternalError)
  2167  }
  2168  
  2169  // getErrorResponse gets in standard error and resource value and
  2170  // provides a encodable populated response values
  2171  func getAPIErrorResponse(ctx context.Context, err APIError, resource, requestID, hostID string) APIErrorResponse {
  2172  	reqInfo := logger.GetReqInfo(ctx)
  2173  	return APIErrorResponse{
  2174  		Code:       err.Code,
  2175  		Message:    err.Description,
  2176  		BucketName: reqInfo.BucketName,
  2177  		Key:        reqInfo.ObjectName,
  2178  		Resource:   resource,
  2179  		Region:     globalServerRegion,
  2180  		RequestID:  requestID,
  2181  		HostID:     hostID,
  2182  	}
  2183  }