diff --git a/src/debug/manager.rs b/src/debug/manager.rs index 36f989f..811d67c 100644 --- a/src/debug/manager.rs +++ b/src/debug/manager.rs @@ -24,6 +24,16 @@ impl StaticContextManager { etag_if_none_match: &EtagIfNoneMatch<'_>, name: S, ) -> StaticResponse { + self.try_build(etag_if_none_match, name).unwrap() + } + + /// Attempt to build a `StaticResponse`. + #[inline] + pub fn try_build>( + &self, + etag_if_none_match: &EtagIfNoneMatch<'_>, + name: S, + ) -> Result { self.resources .lock() .unwrap_or_else(PoisonError::into_inner) @@ -35,6 +45,5 @@ impl StaticContextManager { StaticResponse::build(&resource.0, resource.1.clone(), resource.2) } }) - .unwrap() } } diff --git a/src/release/manager.rs b/src/release/manager.rs index 3ebbd90..26f2562 100644 --- a/src/release/manager.rs +++ b/src/release/manager.rs @@ -22,6 +22,16 @@ impl StaticContextManager { etag_if_none_match: &EtagIfNoneMatch<'_>, name: S, ) -> StaticResponse { + self.try_build(etag_if_none_match, name).unwrap() + } + + /// Attempt to build a `StaticResponse`. + #[inline] + pub fn try_build>( + &self, + etag_if_none_match: &EtagIfNoneMatch<'_>, + name: S, + ) -> Result { self.resources .get_resource(name.as_ref()) .map(|resource| { @@ -31,6 +41,6 @@ impl StaticContextManager { StaticResponse::build(&resource.0, resource.1, resource.2) } }) - .unwrap() + .ok_or(std::io::Error::new(std::io::ErrorKind::NotFound, format!("{} not found", name.as_ref()))) } }