From 65102b70c7db3c9f00674ff93645812da87f4e57 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 7 Aug 2023 11:09:51 -0700 Subject: [PATCH] return more useful messages when a server function errors --- packages/fullstack/src/adapters/axum_adapter.rs | 4 ++-- packages/fullstack/src/adapters/warp_adapter.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/fullstack/src/adapters/axum_adapter.rs b/packages/fullstack/src/adapters/axum_adapter.rs index 330d15bc3..a69357c5a 100644 --- a/packages/fullstack/src/adapters/axum_adapter.rs +++ b/packages/fullstack/src/adapters/axum_adapter.rs @@ -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) } diff --git a/packages/fullstack/src/adapters/warp_adapter.rs b/packages/fullstack/src/adapters/warp_adapter.rs index 723314ca3..e4988b591 100644 --- a/packages/fullstack/src/adapters/warp_adapter.rs +++ b/packages/fullstack/src/adapters/warp_adapter.rs @@ -142,8 +142,16 @@ pub fn register_server_fns(server_fn_route: &'static str) -> BoxedFilter<(impl R async move { let req = warp::hyper::Request::from_parts(parts, bytes.into()); service.run(req).await.map_err(|err| { - log::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())) }) } })