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.

76 lines
2.3 KiB

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