diff options
author | Alex Auvolat <alex@adnab.me> | 2020-11-08 15:04:30 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-11-08 15:05:28 +0100 |
commit | a50fa70d45f8b5af68d23d60c3bac2af4ecceb58 (patch) | |
tree | d3014cc2739c5a1bce62ff35efc8417b79ff46ef /src/api/s3_get.rs | |
parent | 54166d2a09f488bff080469160d4df6a78db1a3f (diff) | |
download | garage-a50fa70d45f8b5af68d23d60c3bac2af4ecceb58.tar.gz garage-a50fa70d45f8b5af68d23d60c3bac2af4ecceb58.zip |
Refactor error management in API parterror-refactoring
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) => { |