diff --git a/pkg/api/api_bucket_handlers.go b/pkg/api/api_bucket_handlers.go index 274519bff..c28fd4ae9 100644 --- a/pkg/api/api_bucket_handlers.go +++ b/pkg/api/api_bucket_handlers.go @@ -141,16 +141,11 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques } case drivers.BucketExists: { - writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path) - } - case drivers.ImplementationError: - { - log.Error.Println(err) - writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) + writeErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path) } default: { - log.Error.Println(err) + log.Error.Println(iodine.New(err, nil)) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) } } diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index 33e8cd2b3..fdb837c1c 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -950,6 +950,38 @@ func (s *MySuite) TestListBucketsErrors(c *C) { verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError) } +func (s *MySuite) TestPutBucketHandler(c *C) { + driver := startMockDriver() + typedDriver := driver + defer driver.AssertExpectations(c) + + httpHandler := api.HTTPHandler("", driver) + testServer := httptest.NewServer(httpHandler) + defer testServer.Close() + client := http.Client{} + + typedDriver.On("CreateBucket", "foo").Return(drivers.BucketNameInvalid{}).Once() + request, err := http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString("")) + c.Assert(err, IsNil) + response, err := client.Do(request) + c.Assert(err, IsNil) + verifyError(c, response, "InvalidBucketName", "The specified bucket is not valid.", http.StatusBadRequest) + + typedDriver.On("CreateBucket", "foo").Return(drivers.BucketExists{}).Once() + request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString("")) + c.Assert(err, IsNil) + response, err = client.Do(request) + c.Assert(err, IsNil) + verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict) + + typedDriver.On("CreateBucket", "foo").Return(drivers.BackendCorrupted{}).Once() + request, err = http.NewRequest("PUT", testServer.URL+"/foo", bytes.NewBufferString("")) + c.Assert(err, IsNil) + response, err = client.Do(request) + c.Assert(err, IsNil) + verifyError(c, response, "InternalError", "We encountered an internal error, please try again.", http.StatusInternalServerError) +} + func verifyError(c *C, response *http.Response, code, description string, statusCode int) { data, err := ioutil.ReadAll(response.Body) c.Assert(err, IsNil)