Remove unwraps

This commit is contained in:
Edward Shen 2022-06-02 22:29:09 -07:00
parent dc216a80d5
commit 0132d32507
Signed by: edward
GPG key ID: 19182661E818369F

View file

@ -104,11 +104,8 @@ pub async fn hop(
};
match resolved_template {
Ok(HopAction::Redirect(path)) => Response::builder()
.status(StatusCode::FOUND)
.header(header::LOCATION, &path)
.body(boxed(Full::from(
handlebars
Ok(HopAction::Redirect(path)) => {
let rendered = handlebars
.render_template(
&path,
&template_args::query(utf8_percent_encode(
@ -116,8 +113,12 @@ pub async fn hop(
FRAGMENT_ENCODE_SET,
)),
)
.unwrap(),
))),
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Response::builder()
.status(StatusCode::FOUND)
.header(header::LOCATION, &path)
.body(boxed(Full::from(rendered)))
}
Ok(HopAction::Body(body)) => Response::builder()
.status(StatusCode::OK)
.body(boxed(Full::new(Bytes::from(body)))),
@ -128,13 +129,12 @@ pub async fn hop(
.body(boxed(Full::from("Something went wrong :(\n")))
}
}
.unwrap()
}
RouteResolution::Unresolved => Response::builder()
.status(StatusCode::NOT_FOUND)
.body(boxed(Full::from("not found\n")))
.unwrap(),
.body(boxed(Full::from("not found\n"))),
}
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
}
#[derive(Debug, PartialEq)]