s3api_errors.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package s3api
  2. import (
  3. "encoding/xml"
  4. "net/http"
  5. )
  6. // APIError structure
  7. type APIError struct {
  8. Code string
  9. Description string
  10. HTTPStatusCode int
  11. }
  12. // RESTErrorResponse - error response format
  13. type RESTErrorResponse struct {
  14. XMLName xml.Name `xml:"Error" json:"-"`
  15. Code string `xml:"Code" json:"Code"`
  16. Message string `xml:"Message" json:"Message"`
  17. Resource string `xml:"Resource" json:"Resource"`
  18. RequestID string `xml:"RequestId" json:"RequestId"`
  19. }
  20. // ErrorCode type of error status.
  21. type ErrorCode int
  22. // Error codes, see full list at http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
  23. const (
  24. ErrNone ErrorCode = iota
  25. ErrMethodNotAllowed
  26. ErrBucketNotEmpty
  27. ErrBucketAlreadyExists
  28. ErrBucketAlreadyOwnedByYou
  29. ErrNoSuchBucket
  30. ErrNoSuchUpload
  31. ErrInvalidBucketName
  32. ErrInvalidDigest
  33. ErrInvalidMaxKeys
  34. ErrInvalidMaxUploads
  35. ErrInvalidMaxParts
  36. ErrInvalidPartNumberMarker
  37. ErrInvalidPart
  38. ErrInternalError
  39. ErrInvalidCopyDest
  40. ErrInvalidCopySource
  41. ErrNotImplemented
  42. )
  43. // error code to APIError structure, these fields carry respective
  44. // descriptions for all the error responses.
  45. var errorCodeResponse = map[ErrorCode]APIError{
  46. ErrMethodNotAllowed: {
  47. Code: "MethodNotAllowed",
  48. Description: "The specified method is not allowed against this resource.",
  49. HTTPStatusCode: http.StatusMethodNotAllowed,
  50. },
  51. ErrBucketNotEmpty: {
  52. Code: "BucketNotEmpty",
  53. Description: "The bucket you tried to delete is not empty",
  54. HTTPStatusCode: http.StatusConflict,
  55. },
  56. ErrBucketAlreadyExists: {
  57. Code: "BucketAlreadyExists",
  58. 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.",
  59. HTTPStatusCode: http.StatusConflict,
  60. },
  61. ErrBucketAlreadyOwnedByYou: {
  62. Code: "BucketAlreadyOwnedByYou",
  63. Description: "Your previous request to create the named bucket succeeded and you already own it.",
  64. HTTPStatusCode: http.StatusConflict,
  65. },
  66. ErrInvalidBucketName: {
  67. Code: "InvalidBucketName",
  68. Description: "The specified bucket is not valid.",
  69. HTTPStatusCode: http.StatusBadRequest,
  70. },
  71. ErrInvalidDigest: {
  72. Code: "InvalidDigest",
  73. Description: "The Content-Md5 you specified is not valid.",
  74. HTTPStatusCode: http.StatusBadRequest,
  75. },
  76. ErrInvalidMaxUploads: {
  77. Code: "InvalidArgument",
  78. Description: "Argument max-uploads must be an integer between 0 and 2147483647",
  79. HTTPStatusCode: http.StatusBadRequest,
  80. },
  81. ErrInvalidMaxKeys: {
  82. Code: "InvalidArgument",
  83. Description: "Argument maxKeys must be an integer between 0 and 2147483647",
  84. HTTPStatusCode: http.StatusBadRequest,
  85. },
  86. ErrInvalidMaxParts: {
  87. Code: "InvalidArgument",
  88. Description: "Argument max-parts must be an integer between 0 and 2147483647",
  89. HTTPStatusCode: http.StatusBadRequest,
  90. },
  91. ErrInvalidPartNumberMarker: {
  92. Code: "InvalidArgument",
  93. Description: "Argument partNumberMarker must be an integer.",
  94. HTTPStatusCode: http.StatusBadRequest,
  95. },
  96. ErrNoSuchBucket: {
  97. Code: "NoSuchBucket",
  98. Description: "The specified bucket does not exist",
  99. HTTPStatusCode: http.StatusNotFound,
  100. },
  101. ErrNoSuchUpload: {
  102. Code: "NoSuchUpload",
  103. Description: "The specified multipart upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.",
  104. HTTPStatusCode: http.StatusNotFound,
  105. },
  106. ErrInternalError: {
  107. Code: "InternalError",
  108. Description: "We encountered an internal error, please try again.",
  109. HTTPStatusCode: http.StatusInternalServerError,
  110. },
  111. ErrInvalidPart: {
  112. Code: "InvalidPart",
  113. 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.",
  114. HTTPStatusCode: http.StatusBadRequest,
  115. },
  116. ErrInvalidCopyDest: {
  117. Code: "InvalidRequest",
  118. 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.",
  119. HTTPStatusCode: http.StatusBadRequest,
  120. },
  121. ErrInvalidCopySource: {
  122. Code: "InvalidArgument",
  123. Description: "Copy Source must mention the source bucket and key: sourcebucket/sourcekey.",
  124. HTTPStatusCode: http.StatusBadRequest,
  125. },
  126. ErrNotImplemented: {
  127. Code: "NotImplemented",
  128. Description: "A header you provided implies functionality that is not implemented",
  129. HTTPStatusCode: http.StatusNotImplemented,
  130. },
  131. }
  132. // getAPIError provides API Error for input API error code.
  133. func getAPIError(code ErrorCode) APIError {
  134. return errorCodeResponse[code]
  135. }