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.
260 lines
8.0 KiB
260 lines
8.0 KiB
10 years ago
|
/*
|
||
10 years ago
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
||
10 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
9 years ago
|
package main
|
||
10 years ago
|
|
||
|
import (
|
||
|
"encoding/xml"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
9 years ago
|
// APIError structure
|
||
|
type APIError struct {
|
||
10 years ago
|
Code string
|
||
|
Description string
|
||
10 years ago
|
HTTPStatusCode int
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// APIErrorResponse - error response format
|
||
|
type APIErrorResponse struct {
|
||
10 years ago
|
XMLName xml.Name `xml:"Error" json:"-"`
|
||
|
Code string
|
||
|
Message string
|
||
|
Resource string
|
||
10 years ago
|
RequestID string `xml:"RequestId"`
|
||
|
HostID string `xml:"HostId"`
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
// Error codes, non exhaustive list - http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
|
||
10 years ago
|
const (
|
||
|
AccessDenied = iota
|
||
|
BadDigest
|
||
|
BucketAlreadyExists
|
||
|
EntityTooSmall
|
||
|
EntityTooLarge
|
||
|
IncompleteBody
|
||
|
InternalError
|
||
10 years ago
|
InvalidAccessKeyID
|
||
10 years ago
|
InvalidBucketName
|
||
|
InvalidDigest
|
||
|
InvalidRange
|
||
10 years ago
|
InvalidRequest
|
||
10 years ago
|
InvalidMaxKeys
|
||
|
InvalidMaxUploads
|
||
|
InvalidMaxParts
|
||
|
InvalidPartNumberMarker
|
||
10 years ago
|
MalformedXML
|
||
|
MissingContentLength
|
||
|
MissingRequestBodyError
|
||
|
NoSuchBucket
|
||
|
NoSuchKey
|
||
|
NoSuchUpload
|
||
|
NotImplemented
|
||
|
RequestTimeTooSkewed
|
||
|
SignatureDoesNotMatch
|
||
10 years ago
|
MethodNotAllowed
|
||
10 years ago
|
InvalidPart
|
||
10 years ago
|
InvalidPartOrder
|
||
9 years ago
|
AuthorizationHeaderMalformed
|
||
9 years ago
|
MalformedPOSTRequest
|
||
9 years ago
|
BucketNotEmpty
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
// Error codes, non exhaustive list - standard HTTP errors
|
||
|
const (
|
||
9 years ago
|
NotAcceptable = iota + 31
|
||
10 years ago
|
)
|
||
|
|
||
9 years ago
|
// APIError code to Error structure map
|
||
|
var errorCodeResponse = map[int]APIError{
|
||
10 years ago
|
InvalidMaxUploads: {
|
||
|
Code: "InvalidArgument",
|
||
9 years ago
|
Description: "Argument maxUploads must be an integer between 0 and 2147483647.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
|
InvalidMaxKeys: {
|
||
|
Code: "InvalidArgument",
|
||
9 years ago
|
Description: "Argument maxKeys must be an integer between 0 and 2147483647.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
|
InvalidMaxParts: {
|
||
|
Code: "InvalidArgument",
|
||
9 years ago
|
Description: "Argument maxParts must be an integer between 1 and 10000.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
|
InvalidPartNumberMarker: {
|
||
|
Code: "InvalidArgument",
|
||
9 years ago
|
Description: "Argument partNumberMarker must be an integer.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
10 years ago
|
AccessDenied: {
|
||
|
Code: "AccessDenied",
|
||
9 years ago
|
Description: "Access Denied.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusForbidden,
|
||
10 years ago
|
},
|
||
|
BadDigest: {
|
||
|
Code: "BadDigest",
|
||
|
Description: "The Content-MD5 you specified did not match what we received.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
BucketAlreadyExists: {
|
||
|
Code: "BucketAlreadyExists",
|
||
|
Description: "The requested bucket name is not available.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusConflict,
|
||
10 years ago
|
},
|
||
|
EntityTooSmall: {
|
||
|
Code: "EntityTooSmall",
|
||
|
Description: "Your proposed upload is smaller than the minimum allowed object size.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
EntityTooLarge: {
|
||
|
Code: "EntityTooLarge",
|
||
|
Description: "Your proposed upload exceeds the maximum allowed object size.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
IncompleteBody: {
|
||
|
Code: "IncompleteBody",
|
||
9 years ago
|
Description: "You did not provide the number of bytes specified by the Content-Length HTTP header.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
InternalError: {
|
||
|
Code: "InternalError",
|
||
|
Description: "We encountered an internal error, please try again.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusInternalServerError,
|
||
10 years ago
|
},
|
||
10 years ago
|
InvalidAccessKeyID: {
|
||
|
Code: "InvalidAccessKeyID",
|
||
|
Description: "The access key ID you provided does not exist in our records.",
|
||
|
HTTPStatusCode: http.StatusForbidden,
|
||
10 years ago
|
},
|
||
|
InvalidBucketName: {
|
||
|
Code: "InvalidBucketName",
|
||
|
Description: "The specified bucket is not valid.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
InvalidDigest: {
|
||
|
Code: "InvalidDigest",
|
||
|
Description: "The Content-MD5 you specified is not valid.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
InvalidRange: {
|
||
|
Code: "InvalidRange",
|
||
|
Description: "The requested range cannot be satisfied.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable,
|
||
10 years ago
|
},
|
||
|
MalformedXML: {
|
||
|
Code: "MalformedXML",
|
||
|
Description: "The XML you provided was not well-formed or did not validate against our published schema.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
10 years ago
|
},
|
||
|
MissingContentLength: {
|
||
|
Code: "MissingContentLength",
|
||
|
Description: "You must provide the Content-Length HTTP header.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusLengthRequired,
|
||
10 years ago
|
},
|
||
|
MissingRequestBodyError: {
|
||
|
Code: "MissingRequestBodyError",
|
||
|
Description: "Request body is empty.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusLengthRequired,
|
||
10 years ago
|
},
|
||
|
NoSuchBucket: {
|
||
|
Code: "NoSuchBucket",
|
||
|
Description: "The specified bucket does not exist.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusNotFound,
|
||
10 years ago
|
},
|
||
|
NoSuchKey: {
|
||
|
Code: "NoSuchKey",
|
||
|
Description: "The specified key does not exist.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusNotFound,
|
||
10 years ago
|
},
|
||
|
NoSuchUpload: {
|
||
|
Code: "NoSuchUpload",
|
||
|
Description: "The specified multipart upload does not exist.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusNotFound,
|
||
10 years ago
|
},
|
||
|
NotImplemented: {
|
||
|
Code: "NotImplemented",
|
||
|
Description: "A header you provided implies functionality that is not implemented.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusNotImplemented,
|
||
10 years ago
|
},
|
||
|
RequestTimeTooSkewed: {
|
||
|
Code: "RequestTimeTooSkewed",
|
||
|
Description: "The difference between the request time and the server's time is too large.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusForbidden,
|
||
10 years ago
|
},
|
||
|
SignatureDoesNotMatch: {
|
||
|
Code: "SignatureDoesNotMatch",
|
||
|
Description: "The request signature we calculated does not match the signature you provided.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusForbidden,
|
||
10 years ago
|
},
|
||
10 years ago
|
MethodNotAllowed: {
|
||
|
Code: "MethodNotAllowed",
|
||
|
Description: "The specified method is not allowed against this resource.",
|
||
|
HTTPStatusCode: http.StatusMethodNotAllowed,
|
||
|
},
|
||
10 years ago
|
NotAcceptable: {
|
||
10 years ago
|
Code: "NotAcceptable",
|
||
|
Description: "The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusNotAcceptable,
|
||
|
},
|
||
10 years ago
|
InvalidPart: {
|
||
|
Code: "InvalidPart",
|
||
9 years ago
|
Description: "One or more of the specified parts could not be found.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
10 years ago
|
InvalidPartOrder: {
|
||
|
Code: "InvalidPartOrder",
|
||
|
Description: "The list of parts was not in ascending order. The parts list must be specified in order by part number.",
|
||
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
9 years ago
|
AuthorizationHeaderMalformed: {
|
||
|
Code: "AuthorizationHeaderMalformed",
|
||
|
Description: "The authorization header is malformed; the region is wrong; expecting 'milkyway'.",
|
||
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
9 years ago
|
MalformedPOSTRequest: {
|
||
|
Code: "MalformedPOSTRequest",
|
||
|
Description: "The body of your POST request is not well-formed multipart/form-data.",
|
||
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
},
|
||
9 years ago
|
BucketNotEmpty: {
|
||
|
Code: "BucketNotEmpty",
|
||
|
Description: "The bucket you tried to delete is not empty.",
|
||
|
HTTPStatusCode: http.StatusConflict,
|
||
|
},
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
// errorCodeError provides errorCode to Error. It returns empty if the code provided is unknown
|
||
9 years ago
|
func getErrorCode(code int) APIError {
|
||
10 years ago
|
return errorCodeResponse[code]
|
||
|
}
|
||
|
|
||
10 years ago
|
// getErrorResponse gets in standard error and resource value and
|
||
|
// provides a encodable populated response values
|
||
9 years ago
|
func getErrorResponse(err APIError, resource string) APIErrorResponse {
|
||
|
var data = APIErrorResponse{}
|
||
10 years ago
|
data.Code = err.Code
|
||
|
data.Message = err.Description
|
||
10 years ago
|
if resource != "" {
|
||
|
data.Resource = resource
|
||
|
}
|
||
10 years ago
|
// TODO implement this in future
|
||
10 years ago
|
data.RequestID = "3L137"
|
||
|
data.HostID = "3L137"
|
||
10 years ago
|
|
||
|
return data
|
||
|
}
|