From: Ian Jackson Date: Wed, 30 Mar 2022 20:57:52 +0000 (+0100) Subject: actix Files: change error handling for middleware fixup fn X-Git-Tag: otter-1.0.0~77 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c87239f9c101b9e2689131531315f2a63fdfcde7;p=otter.git actix Files: change error handling for middleware fixup fn Signed-off-by: Ian Jackson --- diff --git a/daemon/main.rs b/daemon/main.rs index 70b6ff1b..e0389eba 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -374,7 +374,17 @@ async fn r_bundle(path: Path<( .set_content_type(ctype.into_mime()) } -#[throws(actix_web::Error)] +#[derive(Error)] +#[error("actix Files produced improper response: {0}")] +#[derive(Debug, Clone, From)] +pub struct FilesImproperResponse(String); + +impl ResponseError for FilesImproperResponse { + fn status_code(&self) -> StatusCode { StatusCode::INTERNAL_SERVER_ERROR } + fn error_response(&self) -> HttpResponse { error_response(self) } +} + +#[throws(FilesImproperResponse)] fn src_ct_fixup(resp: ServiceResponse) -> ServiceResponse { resp } @@ -529,7 +539,7 @@ async fn main() -> Result<(),StartupError> { .add((header::REFERRER_POLICY, "no-referrer")) ) .wrap_fn(|req, svc| { - svc.call(req).map(|resp| resp.and_then(src_ct_fixup)) + svc.call(req).map(|resp| Ok(src_ct_fixup(resp?)?)) }) .wrap(middleware::Logger::default()) ;