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.

82 lines
2.5 KiB

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