diff --git a/integrations/actix/Cargo.toml b/integrations/actix/Cargo.toml index 94a760f40..1128ee0c5 100644 --- a/integrations/actix/Cargo.toml +++ b/integrations/actix/Cargo.toml @@ -14,5 +14,6 @@ leptos = { workspace = true, features = ["ssr"] } leptos_meta = { workspace = true, features = ["ssr"] } leptos_router = { workspace = true, features = ["ssr"] } leptos_integration_utils = { workspace = true } +serde_json = "1" parking_lot = "0.12.1" regex = "1.7.0" diff --git a/integrations/actix/src/lib.rs b/integrations/actix/src/lib.rs index 022d90edd..88ab30c7e 100644 --- a/integrations/actix/src/lib.rs +++ b/integrations/actix/src/lib.rs @@ -264,8 +264,10 @@ pub fn handle_server_fns_with_context( } } } - Err(e) => HttpResponse::InternalServerError() - .body(e.to_string()), + Err(e) => HttpResponse::InternalServerError().body( + serde_json::to_string(&e) + .unwrap_or_else(|_| e.to_string()), + ), } } else { HttpResponse::BadRequest().body(format!( diff --git a/integrations/axum/Cargo.toml b/integrations/axum/Cargo.toml index a2a571787..361b93c08 100644 --- a/integrations/axum/Cargo.toml +++ b/integrations/axum/Cargo.toml @@ -16,5 +16,6 @@ leptos = { workspace = true, features = ["ssr"] } leptos_meta = { workspace = true, features = ["ssr"] } leptos_router = { workspace = true, features = ["ssr"] } leptos_integration_utils = { workspace = true } +serde_json = "1" tokio = { version = "1", features = ["full"] } parking_lot = "0.12.1" diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index ddd983228..e73fdfced 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -411,7 +411,10 @@ async fn handle_server_fns_inner( } Err(e) => Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Full::from(e.to_string())), + .body(Full::from( + serde_json::to_string(&e) + .unwrap_or_else(|_| e.to_string()), + )), } } else { Response::builder() diff --git a/integrations/viz/Cargo.toml b/integrations/viz/Cargo.toml index bebd68f2d..47c22cbec 100644 --- a/integrations/viz/Cargo.toml +++ b/integrations/viz/Cargo.toml @@ -16,5 +16,6 @@ leptos = { workspace = true, features = ["ssr"] } leptos_meta = { workspace = true, features = ["ssr"] } leptos_router = { workspace = true, features = ["ssr"] } leptos_integration_utils = { workspace = true } +serde_json = "1" tokio = { version = "1", features = ["full"] } parking_lot = "0.12.1" diff --git a/integrations/viz/src/lib.rs b/integrations/viz/src/lib.rs index 823e087f6..a6db5358b 100644 --- a/integrations/viz/src/lib.rs +++ b/integrations/viz/src/lib.rs @@ -301,7 +301,10 @@ async fn handle_server_fns_inner( } Err(e) => Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Body::from(e.to_string())), + .body(Body::from( + serde_json::to_string(&e) + .unwrap_or_else(|_| e.to_string()), + )), } } else { Response::builder() diff --git a/leptos_server/src/lib.rs b/leptos_server/src/lib.rs index 021950b4e..78ad1e24e 100644 --- a/leptos_server/src/lib.rs +++ b/leptos_server/src/lib.rs @@ -94,6 +94,7 @@ use std::{ #[cfg(any(feature = "ssr", doc))] type ServerFnTraitObj = server_fn::ServerFnTraitObj; +#[allow(unused)] type ServerFunction = server_fn::ServerFunction; #[cfg(any(feature = "ssr", doc))] diff --git a/server_fn/src/lib.rs b/server_fn/src/lib.rs index dfc87ac3b..f2b3f87b6 100644 --- a/server_fn/src/lib.rs +++ b/server_fn/src/lib.rs @@ -515,11 +515,13 @@ where #[cfg(not(target_arch = "wasm32"))] let status = status.as_u16(); if (500..=599).contains(&status) { + let text = resp.text().await.unwrap_or_default(); #[cfg(target_arch = "wasm32")] let status_text = resp.status_text(); #[cfg(not(target_arch = "wasm32"))] let status_text = status.to_string(); - return Err(ServerFnError::ServerError(status_text)); + return Err(serde_json::from_str(&text) + .unwrap_or(ServerFnError::ServerError(status_text))); } // Decoding the body of the request