mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 12:14:34 -05:00
fix: correctly pass server fn errors to client (#822)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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!(
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -94,6 +94,7 @@ use std::{
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
type ServerFnTraitObj = server_fn::ServerFnTraitObj<Scope>;
|
||||
|
||||
#[allow(unused)]
|
||||
type ServerFunction = server_fn::ServerFunction<Scope>;
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user