Skip to content

Commit

Permalink
error handling for the GCS implementation of RETR (#80)
Browse files Browse the repository at this point in the history
this solves issue #63
  • Loading branch information
robklg authored Nov 1, 2019
1 parent fa840c3 commit a8ef9c8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/storage/cloud_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,28 @@ impl<U: Send> StorageBackend<U> for CloudStorage {
client
.request(request)
.map_err(|_| Error::from(ErrorKind::PermanentFileNotAvailable))
.and_then(|response| response.into_body().map_err(|_| Error::from(ErrorKind::PermanentFileNotAvailable)).concat2())
.and_then(move |body| future::ok(Object::new(body.to_vec())))
.and_then(|response| {
let status = response.status();
response
.into_body()
.map_err(|_| Error::from(ErrorKind::PermanentFileNotAvailable))
.concat2()
.and_then(move |body| {
match status {
// These are the GCS error variants as per https://cloud.google.com/storage/docs/json_api/v1/status-codes
StatusCode::UNAUTHORIZED => future::err(Error::from(ErrorKind::PermanentFileNotAvailable)),
StatusCode::FORBIDDEN => future::err(Error::from(ErrorKind::PermissionDenied)),
StatusCode::NOT_FOUND => future::err(Error::from(ErrorKind::PermanentFileNotAvailable)),
_ => {
if status.is_success() {
future::ok(Object::new(body.to_vec()))
} else {
future::err(Error::from(ErrorKind::LocalError))
}
}
}
})
})
});
Box::new(result)
}
Expand Down

0 comments on commit a8ef9c8

Please sign in to comment.