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.
224 lines
6.7 KiB
224 lines
6.7 KiB
10 years ago
|
/*
|
||
10 years ago
|
* Minimalist Object 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.
|
||
|
*/
|
||
|
|
||
10 years ago
|
package api
|
||
10 years ago
|
|
||
|
import (
|
||
|
"encoding/xml"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
10 years ago
|
// Error structure
|
||
10 years ago
|
type Error struct {
|
||
|
Code string
|
||
|
Description string
|
||
10 years ago
|
HTTPStatusCode int
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
// ErrorResponse - error response format
|
||
10 years ago
|
type ErrorResponse struct {
|
||
|
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
|
MalformedXML
|
||
|
MissingContentLength
|
||
|
MissingRequestBodyError
|
||
|
NoSuchBucket
|
||
|
NoSuchKey
|
||
|
NoSuchUpload
|
||
|
NotImplemented
|
||
|
RequestTimeTooSkewed
|
||
|
SignatureDoesNotMatch
|
||
|
TooManyBuckets
|
||
10 years ago
|
MethodNotAllowed
|
||
10 years ago
|
InvalidPart
|
||
10 years ago
|
InvalidPartOrder
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
// Error codes, non exhaustive list - standard HTTP errors
|
||
|
const (
|
||
10 years ago
|
NotAcceptable = iota + 25
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
// Error code to Error structure map
|
||
10 years ago
|
var errorCodeResponse = map[int]Error{
|
||
|
AccessDenied: {
|
||
|
Code: "AccessDenied",
|
||
|
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",
|
||
|
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
|
},
|
||
|
TooManyBuckets: {
|
||
|
Code: "TooManyBuckets",
|
||
|
Description: "You have attempted to create more buckets than allowed.",
|
||
10 years ago
|
HTTPStatusCode: http.StatusBadRequest,
|
||
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",
|
||
|
Description: "One or more of the specified parts could not be found",
|
||
|
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,
|
||
|
},
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
// errorCodeError provides errorCode to Error. It returns empty if the code provided is unknown
|
||
10 years ago
|
func getErrorCode(code int) Error {
|
||
10 years ago
|
return errorCodeResponse[code]
|
||
|
}
|
||
|
|
||
10 years ago
|
// getErrorResponse gets in standard error and resource value and
|
||
|
// provides a encodable populated response values
|
||
10 years ago
|
func getErrorResponse(err Error, resource string) ErrorResponse {
|
||
|
var data = ErrorResponse{}
|
||
|
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
|
||
|
}
|