return more useful messages when a server function errors
This commit is contained in:
1 parent
a025617db3
commit
65102b70c7
2 files changed
+12
-4
No files matched your search
@@ -263,8 +263,8 @@ where
|
|||||||
let res = service.run(req);
|
let res = service.run(req);
|
||||||
match res.await {
|
match res.await {
|
||||||
Ok(res) => Ok::<_, std::convert::Infallible>(res.map(|b| b.into())),
|
Ok(res) => Ok::<_, std::convert::Infallible>(res.map(|b| b.into())),
|
||||||
Err(_e) => {
|
Err(e) => {
|
||||||
let mut res = Response::new(Body::empty());
|
let mut res = Response::new(Body::from(e.to_string()));
|
||||||
*res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
*res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,8 +142,16 @@ pub fn register_server_fns(server_fn_route: &'static str) -> BoxedFilter<(impl R
|
|||||||
async move {
|
async move {
|
||||||
let req = warp::hyper::Request::from_parts(parts, bytes.into());
|
let req = warp::hyper::Request::from_parts(parts, bytes.into());
|
||||||
service.run(req).await.map_err(|err| {
|
service.run(req).await.map_err(|err| {
|
||||||
log::error!("Server function error: {}", err);
|
struct WarpServerFnError(String);
|
||||||
warp::reject::reject()
|
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()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user