mirror of
https://github.com/minio/minio.git
synced 2024-12-27 15:45:55 -05:00
Merge pull request #502 from fkautz/pr_out_revert_exporting_writeerrorresponse
This commit is contained in:
commit
d11803b125
@ -33,12 +33,12 @@ func (server *minioAPI) isValidOp(w http.ResponseWriter, req *http.Request, acce
|
|||||||
switch iodine.ToError(err).(type) {
|
switch iodine.ToError(err).(type) {
|
||||||
case drivers.BucketNotFound:
|
case drivers.BucketNotFound:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case drivers.BucketNameInvalid:
|
case drivers.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case nil:
|
case nil:
|
||||||
@ -68,7 +68,7 @@ func (server *minioAPI) isValidOp(w http.ResponseWriter, req *http.Request, acce
|
|||||||
func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// verify if bucket allows this operation
|
// verify if bucket allows this operation
|
||||||
@ -98,16 +98,16 @@ func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
}
|
}
|
||||||
case drivers.ObjectNotFound:
|
case drivers.ObjectNotFound:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.ObjectNameInvalid:
|
case drivers.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(iodine.New(err, nil))
|
log.Error.Println(iodine.New(err, nil))
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(iodine.New(err, nil))
|
log.Error.Println(iodine.New(err, nil))
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,14 +150,14 @@ func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// read from 'x-amz-acl'
|
// read from 'x-amz-acl'
|
||||||
aclType := getACLType(req)
|
aclType := getACLType(req)
|
||||||
if aclType == unsupportedACLType {
|
if aclType == unsupportedACLType {
|
||||||
WriteErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,16 +173,16 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
}
|
}
|
||||||
case drivers.BucketNameInvalid:
|
case drivers.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.BucketExists:
|
case drivers.BucketExists:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(iodine.New(err, nil))
|
log.Error.Println(iodine.New(err, nil))
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
func (server *minioAPI) headBucketHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) headBucketHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func validateHandler(conf config.Config, h http.Handler) http.Handler {
|
|||||||
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
acceptsContentType := getContentType(r)
|
acceptsContentType := getContentType(r)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, r, NotAcceptable, acceptsContentType, r.URL.Path)
|
writeErrorResponse(w, r, NotAcceptable, acceptsContentType, r.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// success
|
// success
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
{
|
{
|
||||||
httpRange, err := getRequestedRange(req, metadata.Size)
|
httpRange, err := getRequestedRange(req, metadata.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
WriteErrorResponse(w, req, InvalidRange, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InvalidRange, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch httpRange.start == 0 && httpRange.length == 0 {
|
switch httpRange.start == 0 && httpRange.length == 0 {
|
||||||
@ -73,16 +73,16 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
}
|
}
|
||||||
case drivers.ObjectNotFound:
|
case drivers.ObjectNotFound:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.ObjectNameInvalid:
|
case drivers.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(iodine.New(err, nil))
|
log.Error.Println(iodine.New(err, nil))
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,16 +115,16 @@ func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||||||
}
|
}
|
||||||
case drivers.ObjectNotFound:
|
case drivers.ObjectNotFound:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.ObjectNameInvalid:
|
case drivers.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(iodine.New(err, nil))
|
log.Error.Println(iodine.New(err, nil))
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||||||
func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
if acceptsContentType == unknownContentType {
|
if acceptsContentType == unknownContentType {
|
||||||
WriteErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotAcceptable, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
// get Content-MD5 sent by client and verify if valid
|
// get Content-MD5 sent by client and verify if valid
|
||||||
md5 := req.Header.Get("Content-MD5")
|
md5 := req.Header.Get("Content-MD5")
|
||||||
if !isValidMD5(md5) {
|
if !isValidMD5(md5) {
|
||||||
WriteErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := server.driver.CreateObject(bucket, object, "", md5, req.Body)
|
err := server.driver.CreateObject(bucket, object, "", md5, req.Body)
|
||||||
@ -163,29 +163,29 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
case drivers.ObjectExists:
|
case drivers.ObjectExists:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.BadDigest:
|
case drivers.BadDigest:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, BadDigest, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, BadDigest, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.EntityTooLarge:
|
case drivers.EntityTooLarge:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.InvalidDigest:
|
case drivers.InvalidDigest:
|
||||||
{
|
{
|
||||||
WriteErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
case drivers.ImplementationError:
|
case drivers.ImplementationError:
|
||||||
{
|
{
|
||||||
log.Error.Println(err)
|
log.Error.Println(err)
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(err)
|
log.Error.Println(err)
|
||||||
WriteErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,7 @@ func generateObjectsListResult(bucket string, objects []drivers.ObjectMetadata,
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteErrorResponse writes a formatted error to the user
|
func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int, acceptsContentType contentType, resource string) {
|
||||||
func WriteErrorResponse(w http.ResponseWriter, req *http.Request, errorType int, acceptsContentType contentType, resource string) {
|
|
||||||
error := getErrorCode(errorType)
|
error := getErrorCode(errorType)
|
||||||
errorResponse := getErrorResponse(error, resource)
|
errorResponse := getErrorResponse(error, resource)
|
||||||
// set headers
|
// set headers
|
||||||
|
Loading…
Reference in New Issue
Block a user