mirror of https://github.com/minio/minio.git
API Bucket Handlers errors simplified
This commit is contained in:
parent
33414915a1
commit
318d9d5aa8
|
@ -59,57 +59,19 @@ func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
||||||
}
|
}
|
||||||
case drivers.BucketNotFound:
|
case drivers.BucketNotFound:
|
||||||
{
|
{
|
||||||
// get error
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
||||||
error := getErrorCode(NoSuchBucket)
|
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
|
||||||
|
|
||||||
// write headers
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
|
|
||||||
// write body
|
|
||||||
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedErrorResponse)
|
|
||||||
}
|
}
|
||||||
case drivers.ImplementationError:
|
case drivers.ImplementationError:
|
||||||
{
|
{
|
||||||
// get error
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
error := getErrorCode(InternalError)
|
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
|
||||||
|
|
||||||
// write headers
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
|
|
||||||
// write body
|
|
||||||
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedErrorResponse)
|
|
||||||
}
|
}
|
||||||
case drivers.BucketNameInvalid:
|
case drivers.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
error := getErrorCode(InvalidBucketName)
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
|
||||||
|
|
||||||
// write headers
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
|
|
||||||
// write body
|
|
||||||
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedErrorResponse)
|
|
||||||
}
|
}
|
||||||
case drivers.ObjectNameInvalid:
|
case drivers.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
error := getErrorCode(NoSuchKey)
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||||
errorResponse := getErrorResponse(error, resources.Prefix)
|
|
||||||
|
|
||||||
// write headers
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
|
|
||||||
// write body
|
|
||||||
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedErrorResponse)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,28 +96,13 @@ func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
||||||
}
|
}
|
||||||
case drivers.BackendCorrupted:
|
case drivers.BackendCorrupted:
|
||||||
{
|
{
|
||||||
log.Error.Println(err)
|
log.Error.Println("Backend Corrupted")
|
||||||
// get error
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
errorCode := getErrorCode(InternalError)
|
|
||||||
errorResponse := getErrorResponse(errorCode, "")
|
|
||||||
// write headers
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(errorCode.HTTPStatusCode)
|
|
||||||
// write
|
|
||||||
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedErrorResponse)
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
log.Error.Println(err)
|
log.Error.Println(err)
|
||||||
// get error
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
errorCode := getErrorCode(InternalError)
|
|
||||||
errorResponse := getErrorResponse(errorCode, "")
|
|
||||||
// write headers
|
|
||||||
w.WriteHeader(errorCode.HTTPStatusCode)
|
|
||||||
// write body
|
|
||||||
encodedError := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,40 +127,19 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
||||||
{
|
{
|
||||||
w.Header().Set("Server", "Minio")
|
w.Header().Set("Server", "Minio")
|
||||||
w.Header().Set("Connection", "close")
|
w.Header().Set("Connection", "close")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
case drivers.BucketNameInvalid:
|
case drivers.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
error := getErrorCode(InvalidBucketName)
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
|
||||||
// write header
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
// write object
|
|
||||||
encodedResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedResponse)
|
|
||||||
}
|
}
|
||||||
case drivers.BucketExists:
|
case drivers.BucketExists:
|
||||||
{
|
{
|
||||||
error := getErrorCode(BucketAlreadyExists)
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
|
||||||
// write header
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
// write object
|
|
||||||
encodedResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedResponse)
|
|
||||||
}
|
}
|
||||||
case drivers.ImplementationError:
|
case drivers.ImplementationError:
|
||||||
{
|
{
|
||||||
// Embed errors log on server side
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||||
error := getErrorCode(InternalError)
|
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
|
||||||
// write header
|
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
|
||||||
// write object
|
|
||||||
encodedResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
|
||||||
w.Write(encodedResponse)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue