Merge pull request #1313 from ealmloff/log-server-errors

Return more useful messages when a server function errors
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2023-09-16 12:01:01 -07:00
commit d3775bb82e
2 files changed
+13 -3

No files matched your search

@@ -263,8 +263,8 @@ where
let res = service.run(req);
match res.await {
Ok(res) => Ok::<_, std::convert::Infallible>(res.map(|b| b.into())),
Err(_e) => {
let mut res = Response::new(Body::empty());
Err(e) => {
let mut res = Response::new(Body::from(e.to_string()));
*res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
Ok(res)
}
@@ -143,7 +143,17 @@ pub fn register_server_fns(server_fn_route: &'static str) -> BoxedFilter<(impl R
let req = warp::hyper::Request::from_parts(parts, bytes.into());
service.run(req).await.map_err(|err| {
tracing::error!("Server function error: {}", err);
warp::reject::reject()
struct WarpServerFnError(String);
impl std::fmt::Debug for WarpServerFnError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl warp::reject::Reject for WarpServerFnError {}
warp::reject::custom(WarpServerFnError(err.to_string()))
})
}
})