docs/warnings: improve `ServerFnError` when a server function is not found (#1350)

This commit is contained in:
Greg Johnston 2023-07-14 12:43:08 -04:00 committed by GitHub
parent 10d51a854a
commit 3eed86fbf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 5 deletions

View File

@ -292,7 +292,12 @@ pub fn handle_server_fns_with_context(
} else {
HttpResponse::BadRequest().body(format!(
"Could not find a server function at the route {:?}. \
\n\nIt's likely that you need to call \
\n\nIt's likely that either
1. The API prefix you specify in the `#[server]` \
macro doesn't match the prefix at which your server \
function handler is mounted, or \n2. You are on a \
platform that doesn't support automatic server \
function registration and you need to call \
ServerFn::register_explicit() on the server function \
type, somewhere in your `main` function.",
req.path()

View File

@ -335,9 +335,14 @@ async fn handle_server_fns_inner(
Response::builder().status(StatusCode::BAD_REQUEST).body(
Full::from(format!(
"Could not find a server function at the route \
{fn_name}. \n\nIt's likely that you need to call \
{fn_name}. \n\nIt's likely that either
1. The API prefix you specify in the `#[server]` \
macro doesn't match the prefix at which your server \
function handler is mounted, or \n2. You are on a \
platform that doesn't support automatic server \
function registration and you need to call \
ServerFn::register_explicit() on the server function \
type, somewhere in your `main` function."
type, somewhere in your `main` function.",
)),
)
}

View File

@ -312,10 +312,17 @@ async fn handle_server_fns_inner(
.body(Body::from(format!(
"Could not find a server function at the \
route {fn_name}. \n\nIt's likely that \
you need to call \
either
1. The API prefix you specify in the \
`#[server]` macro doesn't match the \
prefix at which your server function \
handler is mounted, or \n2. You are on a \
platform that doesn't support automatic \
server function registration and you \
need to call \
ServerFn::register_explicit() on the \
server function type, somewhere in your \
`main` function."
`main` function.",
)))
}
.expect("could not build Response");

View File

@ -608,6 +608,12 @@ where
#[cfg(not(target_arch = "wasm32"))]
let binary = binary.as_ref();
if status == 400 {
return Err(ServerFnError::ServerError(
"No server function was found at this URL.".to_string(),
));
}
ciborium::de::from_reader(binary)
.map_err(|e| ServerFnError::Deserialization(e.to_string()))
} else {
@ -616,6 +622,10 @@ where
.await
.map_err(|e| ServerFnError::Deserialization(e.to_string()))?;
if status == 400 {
return Err(ServerFnError::ServerError(text));
}
let mut deserializer = JSONDeserializer::from_str(&text);
T::deserialize(&mut deserializer)
.map_err(|e| ServerFnError::Deserialization(e.to_string()))