You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6 KiB

7 years ago
7 years ago
7 years ago
  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. ErrInvalidBucketName
  31. ErrInvalidDigest
  32. ErrInternalError
  33. )
  34. // error code to APIError structure, these fields carry respective
  35. // descriptions for all the error responses.
  36. var errorCodeResponse = map[ErrorCode]APIError{
  37. ErrMethodNotAllowed: {
  38. Code: "MethodNotAllowed",
  39. Description: "The specified method is not allowed against this resource.",
  40. HTTPStatusCode: http.StatusMethodNotAllowed,
  41. },
  42. ErrBucketNotEmpty: {
  43. Code: "BucketNotEmpty",
  44. Description: "The bucket you tried to delete is not empty",
  45. HTTPStatusCode: http.StatusConflict,
  46. },
  47. ErrBucketAlreadyExists: {
  48. Code: "BucketAlreadyExists",
  49. 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.",
  50. HTTPStatusCode: http.StatusConflict,
  51. },
  52. ErrBucketAlreadyOwnedByYou: {
  53. Code: "BucketAlreadyOwnedByYou",
  54. Description: "Your previous request to create the named bucket succeeded and you already own it.",
  55. HTTPStatusCode: http.StatusConflict,
  56. },
  57. ErrInvalidBucketName: {
  58. Code: "InvalidBucketName",
  59. Description: "The specified bucket is not valid.",
  60. HTTPStatusCode: http.StatusBadRequest,
  61. },
  62. ErrInvalidDigest: {
  63. Code: "InvalidDigest",
  64. Description: "The Content-Md5 you specified is not valid.",
  65. HTTPStatusCode: http.StatusBadRequest,
  66. },
  67. ErrNoSuchBucket: {
  68. Code: "NoSuchBucket",
  69. Description: "The specified bucket does not exist",
  70. HTTPStatusCode: http.StatusNotFound,
  71. },
  72. ErrInternalError: {
  73. Code: "InternalError",
  74. Description: "We encountered an internal error, please try again.",
  75. HTTPStatusCode: http.StatusInternalServerError,
  76. },
  77. }
  78. // getAPIError provides API Error for input API error code.
  79. func getAPIError(code ErrorCode) APIError {
  80. return errorCodeResponse[code]
  81. }