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 {
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)
}
// 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 == "" ||
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
// 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 {
// 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)
}
}
// 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.