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