Add errorIf for all API handlers to print call trace upon errors

master
Harshavardhana 9 years ago
parent e510e97f28
commit 2721bef8da
  1. 132
      server-api-bucket-handlers.go
  2. 333
      server-api-object-handlers.go

@ -30,6 +30,7 @@ func (api MinioAPI) isValidOp(w http.ResponseWriter, req *http.Request, acceptsC
bucketMetadata, err := api.Donut.GetBucketMetadata(bucket, nil) bucketMetadata, err := api.Donut.GetBucketMetadata(bucket, nil)
if err != nil { if err != nil {
errorIf(err.Trace(), "GetBucketMetadata failed.", nil)
switch err.ToGoError().(type) { switch err.ToGoError().(type) {
case donut.BucketNotFound: case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
@ -38,7 +39,6 @@ func (api MinioAPI) isValidOp(w http.ResponseWriter, req *http.Request, acceptsC
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
return false return false
default: default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return false return false
} }
@ -100,31 +100,32 @@ func (api MinioAPI) ListMultipartUploadsHandler(w http.ResponseWriter, req *http
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
resources, err := api.Donut.ListMultipartUploads(bucket, resources, signature) resources, err := api.Donut.ListMultipartUploads(bucket, resources, signature)
if err == nil { if err != nil {
// generate response errorIf(err.Trace(), "ListMultipartUploads failed.", nil)
response := generateListMultipartUploadsResponse(bucket, resources) switch err.ToGoError().(type) {
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType) case donut.SignatureDoesNotMatch:
// write headers writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse)) case donut.BucketNotFound:
// write body writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
w.Write(encodedSuccessResponse) default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { // generate response
case donut.SignatureDoesNotMatch: response := generateListMultipartUploadsResponse(bucket, resources)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
case donut.BucketNotFound: // write headers
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path) setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
default: // write body
// log.Error.Println(err.Trace()) w.Write(encodedSuccessResponse)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// ListObjectsHandler - GET Bucket (List Objects) // ListObjectsHandler - GET Bucket (List Objects)
@ -171,6 +172,7 @@ func (api MinioAPI) ListObjectsHandler(w http.ResponseWriter, req *http.Request)
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
@ -199,7 +201,7 @@ func (api MinioAPI) ListObjectsHandler(w http.ResponseWriter, req *http.Request)
case donut.ObjectNameInvalid: case donut.ObjectNameInvalid:
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
default: default:
// log.Error.Println(err.Trace()) errorIf(err.Trace(), "ListObjects failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
} }
} }
@ -232,6 +234,7 @@ func (api MinioAPI) ListBucketsHandler(w http.ResponseWriter, req *http.Request)
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
@ -252,7 +255,7 @@ func (api MinioAPI) ListBucketsHandler(w http.ResponseWriter, req *http.Request)
case donut.SignatureDoesNotMatch: case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
default: default:
// log.Error.Println(err.Trace()) errorIf(err.Trace(), "ListBuckets failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
} }
} }
@ -298,6 +301,7 @@ func (api MinioAPI) PutBucketHandler(w http.ResponseWriter, req *http.Request) {
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
@ -314,25 +318,25 @@ func (api MinioAPI) PutBucketHandler(w http.ResponseWriter, req *http.Request) {
} }
err := api.Donut.MakeBucket(bucket, getACLTypeString(aclType), req.Body, signature) err := api.Donut.MakeBucket(bucket, getACLTypeString(aclType), req.Body, signature)
if err == nil { if err != nil {
// Make sure to add Location information here only for bucket errorIf(err.Trace(), "MakeBucket failed.", nil)
w.Header().Set("Location", "/"+bucket) switch err.ToGoError().(type) {
writeSuccessResponse(w, acceptsContentType) case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.TooManyBuckets:
writeErrorResponse(w, req, TooManyBuckets, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.BucketExists:
writeErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { // Make sure to add Location information here only for bucket
case donut.SignatureDoesNotMatch: w.Header().Set("Location", "/"+bucket)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) writeSuccessResponse(w, acceptsContentType)
case donut.TooManyBuckets:
writeErrorResponse(w, req, TooManyBuckets, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.BucketExists:
writeErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// PutBucketACLHandler - PUT Bucket ACL // PutBucketACLHandler - PUT Bucket ACL
@ -366,27 +370,28 @@ func (api MinioAPI) PutBucketACLHandler(w http.ResponseWriter, req *http.Request
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
err := api.Donut.SetBucketMetadata(bucket, map[string]string{"acl": getACLTypeString(aclType)}, signature) err := api.Donut.SetBucketMetadata(bucket, map[string]string{"acl": getACLTypeString(aclType)}, signature)
if err == nil { if err != nil {
writeSuccessResponse(w, acceptsContentType) errorIf(err.Trace(), "PutBucketACL failed.", nil)
switch err.ToGoError().(type) {
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { writeSuccessResponse(w, acceptsContentType)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// HeadBucketHandler - HEAD Bucket // HeadBucketHandler - HEAD Bucket
@ -416,25 +421,26 @@ func (api MinioAPI) HeadBucketHandler(w http.ResponseWriter, req *http.Request)
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
_, err := api.Donut.GetBucketMetadata(bucket, signature) _, err := api.Donut.GetBucketMetadata(bucket, signature)
if err == nil { if err != nil {
writeSuccessResponse(w, acceptsContentType) errorIf(err.Trace(), "GetBucketMetadata failed.", nil)
switch err.ToGoError().(type) {
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { writeSuccessResponse(w, acceptsContentType)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }

@ -59,41 +59,41 @@ func (api MinioAPI) GetObjectHandler(w http.ResponseWriter, req *http.Request) {
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
metadata, err := api.Donut.GetObjectMetadata(bucket, object, signature) metadata, err := api.Donut.GetObjectMetadata(bucket, object, signature)
if err == nil { if err != nil {
var hrange *httpRange errorIf(err.Trace(), "GetObject failed.", nil)
hrange, err = getRequestedRange(req.Header.Get("Range"), metadata.Size) switch err.ToGoError().(type) {
if err != nil { case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, InvalidRange, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
return case donut.BucketNameInvalid:
} writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
setObjectHeaders(w, metadata, hrange) case donut.BucketNotFound:
if _, err = api.Donut.GetObject(w, bucket, object, hrange.start, hrange.length); err != nil { writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
// unable to write headers, we've already printed data. Just close the connection. case donut.ObjectNotFound:
// log.Error.Println(err.Trace()) writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
return case donut.ObjectNameInvalid:
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
} }
return return
} }
switch err.ToGoError().(type) { var hrange *httpRange
case donut.SignatureDoesNotMatch: hrange, err = getRequestedRange(req.Header.Get("Range"), metadata.Size)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) if err != nil {
case donut.BucketNameInvalid: writeErrorResponse(w, req, InvalidRange, acceptsContentType, req.URL.Path)
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path) return
case donut.BucketNotFound: }
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path) setObjectHeaders(w, metadata, hrange)
case donut.ObjectNotFound: if _, err = api.Donut.GetObject(w, bucket, object, hrange.start, hrange.length); err != nil {
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path) errorIf(err.Trace(), "GetObject failed.", nil)
case donut.ObjectNameInvalid: return
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
} }
} }
@ -126,32 +126,33 @@ func (api MinioAPI) HeadObjectHandler(w http.ResponseWriter, req *http.Request)
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
metadata, err := api.Donut.GetObjectMetadata(bucket, object, signature) metadata, err := api.Donut.GetObjectMetadata(bucket, object, signature)
if err == nil { if err != nil {
setObjectHeaders(w, metadata, nil) errorIf(err.Trace(), "GetObjectMetadata failed.", nil)
w.WriteHeader(http.StatusOK) switch err.ToGoError().(type) {
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
case donut.ObjectNotFound:
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
case donut.ObjectNameInvalid:
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { setObjectHeaders(w, metadata, nil)
case donut.SignatureDoesNotMatch: w.WriteHeader(http.StatusOK)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
case donut.ObjectNotFound:
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
case donut.ObjectNameInvalid:
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// PutObjectHandler - PUT Object // PutObjectHandler - PUT Object
@ -220,40 +221,41 @@ func (api MinioAPI) PutObjectHandler(w http.ResponseWriter, req *http.Request) {
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
metadata, err := api.Donut.CreateObject(bucket, object, md5, sizeInt64, req.Body, nil, signature) metadata, err := api.Donut.CreateObject(bucket, object, md5, sizeInt64, req.Body, nil, signature)
if err == nil { if err != nil {
w.Header().Set("ETag", metadata.MD5Sum) errorIf(err.Trace(), "CreateObject failed.", nil)
writeSuccessResponse(w, acceptsContentType) switch err.ToGoError().(type) {
case donut.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.ObjectExists:
writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path)
case donut.BadDigest:
writeErrorResponse(w, req, BadDigest, acceptsContentType, req.URL.Path)
case donut.MissingDateHeader:
writeErrorResponse(w, req, RequestTimeTooSkewed, acceptsContentType, req.URL.Path)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.IncompleteBody:
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
case donut.EntityTooLarge:
writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
case donut.InvalidDigest:
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { w.Header().Set("ETag", metadata.MD5Sum)
case donut.BucketNotFound: writeSuccessResponse(w, acceptsContentType)
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
case donut.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
case donut.ObjectExists:
writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path)
case donut.BadDigest:
writeErrorResponse(w, req, BadDigest, acceptsContentType, req.URL.Path)
case donut.MissingDateHeader:
writeErrorResponse(w, req, RequestTimeTooSkewed, acceptsContentType, req.URL.Path)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.IncompleteBody:
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
case donut.EntityTooLarge:
writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
case donut.InvalidDigest:
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
/// Multipart API /// Multipart API
@ -290,30 +292,32 @@ func (api MinioAPI) NewMultipartUploadHandler(w http.ResponseWriter, req *http.R
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
uploadID, err := api.Donut.NewMultipartUpload(bucket, object, req.Header.Get("Content-Type"), signature) uploadID, err := api.Donut.NewMultipartUpload(bucket, object, req.Header.Get("Content-Type"), signature)
if err == nil { if err != nil {
response := generateInitiateMultipartUploadResponse(bucket, object, uploadID) errorIf(err.Trace(), "NewMultipartUpload failed.", nil)
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType) switch err.ToGoError().(type) {
// write headers case donut.SignatureDoesNotMatch:
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse)) writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
// write body case donut.ObjectExists:
w.Write(encodedSuccessResponse) writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) {
case donut.SignatureDoesNotMatch: response := generateInitiateMultipartUploadResponse(bucket, object, uploadID)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
case donut.ObjectExists: // write headers
writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path) setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
default: // write body
// log.Error.Println(err.Trace()) w.Write(encodedSuccessResponse)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// PutObjectPartHandler - Upload part // PutObjectPartHandler - Upload part
@ -375,6 +379,7 @@ func (api MinioAPI) PutObjectPartHandler(w http.ResponseWriter, req *http.Reques
partID, err = strconv.Atoi(partIDString) partID, err = strconv.Atoi(partIDString)
if err != nil { if err != nil {
writeErrorResponse(w, req, InvalidPart, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InvalidPart, acceptsContentType, req.URL.Path)
return
} }
} }
@ -384,36 +389,37 @@ func (api MinioAPI) PutObjectPartHandler(w http.ResponseWriter, req *http.Reques
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
calculatedMD5, err := api.Donut.CreateObjectPart(bucket, object, uploadID, partID, "", md5, sizeInt64, req.Body, signature) calculatedMD5, err := api.Donut.CreateObjectPart(bucket, object, uploadID, partID, "", md5, sizeInt64, req.Body, signature)
if err == nil { if err != nil {
w.Header().Set("ETag", calculatedMD5) errorIf(err.Trace(), "CreateObjectPart failed.", nil)
writeSuccessResponse(w, acceptsContentType) switch err.ToGoError().(type) {
case donut.InvalidUploadID:
writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path)
case donut.ObjectExists:
writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path)
case donut.BadDigest:
writeErrorResponse(w, req, BadDigest, acceptsContentType, req.URL.Path)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.IncompleteBody:
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
case donut.EntityTooLarge:
writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
case donut.InvalidDigest:
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { w.Header().Set("ETag", calculatedMD5)
case donut.InvalidUploadID: writeSuccessResponse(w, acceptsContentType)
writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path)
case donut.ObjectExists:
writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path)
case donut.BadDigest:
writeErrorResponse(w, req, BadDigest, acceptsContentType, req.URL.Path)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.IncompleteBody:
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
case donut.EntityTooLarge:
writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
case donut.InvalidDigest:
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// AbortMultipartUploadHandler - Abort multipart upload // AbortMultipartUploadHandler - Abort multipart upload
@ -444,26 +450,27 @@ func (api MinioAPI) AbortMultipartUploadHandler(w http.ResponseWriter, req *http
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
err := api.Donut.AbortMultipartUpload(bucket, object, objectResourcesMetadata.UploadID, signature) err := api.Donut.AbortMultipartUpload(bucket, object, objectResourcesMetadata.UploadID, signature)
if err == nil { if err != nil {
setCommonHeaders(w, getContentTypeString(acceptsContentType), 0) errorIf(err.Trace(), "AbortMutlipartUpload failed.", nil)
w.WriteHeader(http.StatusNoContent) switch err.ToGoError().(type) {
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.InvalidUploadID:
writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { setCommonHeaders(w, getContentTypeString(acceptsContentType), 0)
case donut.SignatureDoesNotMatch: w.WriteHeader(http.StatusNoContent)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.InvalidUploadID:
writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// ListObjectPartsHandler - List object parts // ListObjectPartsHandler - List object parts
@ -505,30 +512,31 @@ func (api MinioAPI) ListObjectPartsHandler(w http.ResponseWriter, req *http.Requ
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
objectResourcesMetadata, err := api.Donut.ListObjectParts(bucket, object, objectResourcesMetadata, signature) objectResourcesMetadata, err := api.Donut.ListObjectParts(bucket, object, objectResourcesMetadata, signature)
if err == nil { if err != nil {
response := generateListPartsResponse(objectResourcesMetadata) errorIf(err.Trace(), "ListObjectParts failed.", nil)
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType) switch err.ToGoError().(type) {
// write headers case donut.SignatureDoesNotMatch:
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse)) writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
// write body case donut.InvalidUploadID:
w.Write(encodedSuccessResponse) writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { response := generateListPartsResponse(objectResourcesMetadata)
case donut.SignatureDoesNotMatch: encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) // write headers
case donut.InvalidUploadID: setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path) // write body
default: w.Write(encodedSuccessResponse)
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
// CompleteMultipartUploadHandler - Complete multipart upload // CompleteMultipartUploadHandler - Complete multipart upload
@ -559,39 +567,40 @@ func (api MinioAPI) CompleteMultipartUploadHandler(w http.ResponseWriter, req *h
var err *probe.Error var err *probe.Error
signature, err = initSignatureV4(req) signature, err = initSignatureV4(req)
if err != nil { if err != nil {
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
return return
} }
} }
metadata, err := api.Donut.CompleteMultipartUpload(bucket, object, objectResourcesMetadata.UploadID, req.Body, signature) metadata, err := api.Donut.CompleteMultipartUpload(bucket, object, objectResourcesMetadata.UploadID, req.Body, signature)
if err == nil { if err != nil {
response := generateCompleteMultpartUploadResponse(bucket, object, "", metadata.MD5Sum) errorIf(err.Trace(), "CompleteMultipartUpload failed.", nil)
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType) switch err.ToGoError().(type) {
// write headers case donut.InvalidUploadID:
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse)) writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path)
// write body case donut.InvalidPart:
w.Write(encodedSuccessResponse) writeErrorResponse(w, req, InvalidPart, acceptsContentType, req.URL.Path)
case donut.InvalidPartOrder:
writeErrorResponse(w, req, InvalidPartOrder, acceptsContentType, req.URL.Path)
case donut.MissingDateHeader:
writeErrorResponse(w, req, RequestTimeTooSkewed, acceptsContentType, req.URL.Path)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.IncompleteBody:
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
case donut.MalformedXML:
writeErrorResponse(w, req, MalformedXML, acceptsContentType, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
return return
} }
switch err.ToGoError().(type) { response := generateCompleteMultpartUploadResponse(bucket, object, "", metadata.MD5Sum)
case donut.InvalidUploadID: encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
writeErrorResponse(w, req, NoSuchUpload, acceptsContentType, req.URL.Path) // write headers
case donut.InvalidPart: setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
writeErrorResponse(w, req, InvalidPart, acceptsContentType, req.URL.Path) // write body
case donut.InvalidPartOrder: w.Write(encodedSuccessResponse)
writeErrorResponse(w, req, InvalidPartOrder, acceptsContentType, req.URL.Path)
case donut.MissingDateHeader:
writeErrorResponse(w, req, RequestTimeTooSkewed, acceptsContentType, req.URL.Path)
case donut.SignatureDoesNotMatch:
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
case donut.IncompleteBody:
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
case donut.MalformedXML:
writeErrorResponse(w, req, MalformedXML, acceptsContentType, req.URL.Path)
default:
// log.Error.Println(err.Trace())
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
}
} }
/// Delete API /// Delete API

Loading…
Cancel
Save