mirror of https://github.com/minio/minio.git
Make sure in API we handle all error type exclusively, and return certain values exclusively
This commit is contained in:
parent
0491e1bbf1
commit
a56098b8c9
|
@ -73,6 +73,11 @@ func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||
{
|
||||
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,6 +88,7 @@ func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||
func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
||||
acceptsContentType := getContentType(req)
|
||||
buckets, err := server.driver.ListBuckets()
|
||||
// cannot fallthrough in (type) switch :(
|
||||
switch err := err.(type) {
|
||||
case nil:
|
||||
{
|
||||
|
@ -96,7 +102,7 @@ func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||
}
|
||||
case drivers.BackendCorrupted:
|
||||
{
|
||||
log.Error.Println("Backend Corrupted")
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
|
@ -139,6 +145,12 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
|||
}
|
||||
case drivers.ImplementationError:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,11 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||
{
|
||||
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
case drivers.ImplementationError:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
|
@ -105,8 +110,10 @@ func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||
metadata, err := server.driver.GetObjectMetadata(bucket, object, "")
|
||||
switch err := err.(type) {
|
||||
case nil:
|
||||
setObjectHeaders(w, metadata)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
{
|
||||
setObjectHeaders(w, metadata)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
case drivers.ObjectNotFound:
|
||||
{
|
||||
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
||||
|
@ -120,6 +127,11 @@ func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,5 +186,10 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||
{
|
||||
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.Error.Println(err)
|
||||
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,13 @@ func (d donutDriver) GetPartialObject(w io.Writer, bucket, object string, start,
|
|||
// GetObjectMetadata retrieves an object's metadata
|
||||
func (d donutDriver) GetObjectMetadata(bucket, key string, prefix string) (drivers.ObjectMetadata, error) {
|
||||
metadata, err := d.donut.GetObjectMetadata(bucket, key)
|
||||
if err != nil {
|
||||
// return ObjectNotFound quickly on an error, API needs this to handle invalid requests
|
||||
return drivers.ObjectMetadata{}, drivers.ObjectNotFound{
|
||||
Bucket: bucket,
|
||||
Object: key,
|
||||
}
|
||||
}
|
||||
created, err := time.Parse(time.RFC3339Nano, metadata["sys.created"])
|
||||
if err != nil {
|
||||
return drivers.ObjectMetadata{}, err
|
||||
|
|
Loading…
Reference in New Issue