3220: Fix HTTP status codes.
authorTom Clegg <tom@curoverse.com>
Thu, 10 Jul 2014 17:33:00 +0000 (13:33 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 10 Jul 2014 17:33:00 +0000 (13:33 -0400)
services/keep/src/keep/keep.go
services/keep/src/keep/keep_test.go

index 67c628d128db0c3fd4fc40570f56e9f2a4fb33cd..4be2f43cb821577332b7c84c56522b69a9a0b69e 100644 (file)
@@ -71,15 +71,15 @@ type KeepError struct {
 
 var (
        BadRequestError = &KeepError{400, "Bad Request"}
-       CollisionError  = &KeepError{400, "Collision"}
-       MD5Error        = &KeepError{401, "MD5 Failure"}
-       PermissionError = &KeepError{401, "Permission denied"}
-       CorruptError    = &KeepError{402, "Corruption"}
-       ExpiredError    = &KeepError{403, "Expired permission signature"}
+       CollisionError  = &KeepError{500, "Collision"}
+       RequestHashError= &KeepError{422, "Hash mismatch in request"}
+       PermissionError = &KeepError{403, "Forbidden"}
+       DiskHashError   = &KeepError{500, "Hash mismatch in stored data"}
+       ExpiredError    = &KeepError{401, "Expired permission signature"}
        NotFoundError   = &KeepError{404, "Not Found"}
        GenericError    = &KeepError{500, "Fail"}
        FullError       = &KeepError{503, "Full"}
-       TooLongError    = &KeepError{504, "Too Long"}
+       TooLongError    = &KeepError{504, "Timeout"}
 )
 
 func (e *KeepError) Error() string {
@@ -412,7 +412,7 @@ func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 
        if err != nil {
                // This type assertion is safe because the only errors
-               // GetBlock can return are CorruptError or NotFoundError.
+               // GetBlock can return are DiskHashError or NotFoundError.
                if err == NotFoundError {
                        log.Printf("%s: not found, giving up\n", hash)
                }
@@ -480,7 +480,7 @@ func IndexHandler(resp http.ResponseWriter, req *http.Request) {
 
        // Only the data manager may issue /index requests,
        // and only if enforce_permissions is enabled.
-       // All other requests return 403 Permission denied.
+       // All other requests return 403 Forbidden.
        api_token := GetApiToken(req)
        if !enforce_permissions ||
                api_token == "" ||
@@ -619,10 +619,10 @@ func GetBlock(hash string) ([]byte, error) {
    On success, PutBlock returns nil.
    On failure, it returns a KeepError with one of the following codes:
 
-   400 Collision
+   500 Collision
           A different block with the same hash already exists on this
           Keep server.
-   401 MD5Fail
+   422 MD5Fail
           The MD5 hash of the BLOCK does not match the argument HASH.
    503 Full
           There was not enough space left in any Keep volume to store
@@ -643,7 +643,7 @@ func PutBlock(block []byte, hash string) error {
 
        // If we already have a block on disk under this identifier, return
        // success (but check for MD5 collisions).
-       // The only errors that GetBlock can return are ErrCorrupt and ErrNotFound.
+       // The only errors that GetBlock can return are DiskHashError and NotFoundError.
        // In either case, we want to write our new (good) block to disk,
        // so there is nothing special to do if err != nil.
        if oldblock, err := GetBlock(hash); err == nil {
index 7a787c10874b2b06a26f531073f29aa1f55e77b7..de189b659c0b10db9cfac8490c689ec87537d48b 100644 (file)
@@ -100,8 +100,8 @@ func TestGetBlockCorrupt(t *testing.T) {
 
        // Check that GetBlock returns failure.
        result, err := GetBlock(TEST_HASH)
-       if err != CorruptError {
-               t.Errorf("Expected CorruptError, got %v (buf: %v)", err, result)
+       if err != DiskHashError {
+               t.Errorf("Expected DiskHashError, got %v (buf: %v)", err, result)
        }
 }
 
@@ -178,8 +178,8 @@ func TestPutBlockMD5Fail(t *testing.T) {
 
        // Check that PutBlock returns the expected error when the hash does
        // not match the block.
-       if err := PutBlock(BAD_BLOCK, TEST_HASH); err != MD5Error {
-               t.Error("Expected MD5Error, got %v", err)
+       if err := PutBlock(BAD_BLOCK, TEST_HASH); err != RequestHashError {
+               t.Error("Expected RequestHashError, got %v", err)
        }
 
        // Confirm that GetBlock fails to return anything.