diff options
author | Alex <alex@adnab.me> | 2020-11-08 18:04:52 +0100 |
---|---|---|
committer | Alex <alex@adnab.me> | 2020-11-08 18:04:52 +0100 |
commit | 045009da9b7ac4198574bd5aa256c11cfe4ae469 (patch) | |
tree | d3014cc2739c5a1bce62ff35efc8417b79ff46ef /src/api/s3_get.rs | |
parent | 54166d2a09f488bff080469160d4df6a78db1a3f (diff) | |
parent | a50fa70d45f8b5af68d23d60c3bac2af4ecceb58 (diff) | |
download | garage-045009da9b7ac4198574bd5aa256c11cfe4ae469.tar.gz garage-045009da9b7ac4198574bd5aa256c11cfe4ae469.zip |
Merge pull request 'Refactor error management in API part' (#10) from error-refactoring into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/10
Diffstat (limited to 'src/api/s3_get.rs')
-rw-r--r-- | src/api/s3_get.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs index 68558dbe..71c656f2 100644 --- a/src/api/s3_get.rs +++ b/src/api/s3_get.rs @@ -5,13 +5,13 @@ use futures::stream::*; use hyper::body::Bytes; use hyper::{Body, Request, Response, StatusCode}; -use garage_util::error::Error; - use garage_table::EmptyKey; use garage_model::garage::Garage; use garage_model::object_table::*; +use crate::error::*; + fn object_headers( version: &ObjectVersion, version_meta: &ObjectVersionMeta, @@ -111,11 +111,8 @@ pub async fn handle_get( let range = match req.headers().get("range") { Some(range) => { - let range_str = range - .to_str() - .map_err(|e| Error::BadRequest(format!("Invalid range header: {}", e)))?; - let mut ranges = http_range::HttpRange::parse(range_str, last_v_meta.size) - .map_err(|_e| Error::BadRequest(format!("Invalid range")))?; + let range_str = range.to_str()?; + let mut ranges = http_range::HttpRange::parse(range_str, last_v_meta.size)?; if ranges.len() > 1 { return Err(Error::BadRequest(format!("Multiple ranges not supported"))); } else { @@ -210,7 +207,9 @@ pub async fn handle_get_range( let body: Body = Body::from(bytes[begin as usize..end as usize].to_vec()); Ok(resp_builder.body(body)?) } else { - Err(Error::Message(format!("Internal error: requested range not present in inline bytes when it should have been"))) + None.ok_or_internal_error( + "Requested range not present in inline bytes when it should have been", + ) } } ObjectVersionData::FirstBlock(_meta, _first_block_hash) => { |