Skip to content

Commit

Permalink
Uniquely identify serverfn errors in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 committed Jan 6, 2024
1 parent 3b2e898 commit 554a593
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion integrations/actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub fn handle_server_fns_with_context(
HttpResponse::SeeOther()
.insert_header((
header::LOCATION,
url.with_server_fn(&e).as_str(),
url.with_server_fn(&e, path.as_str()).as_str(),
))
.finish()
} else {
Expand Down
4 changes: 2 additions & 2 deletions integrations/axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async fn handle_server_fns_inner(
// Axum Path extractor doesn't remove the first slash from the path, while Actix does
let fn_name = fn_name
.strip_prefix('/')
.map(|fn_name| fn_name.to_string())
.map(ToString::to_string)
.unwrap_or(fn_name);

let (tx, rx) = futures::channel::oneshot::channel();
Expand Down Expand Up @@ -388,7 +388,7 @@ async fn handle_server_fns_inner(
.status(StatusCode::SEE_OTHER)
.header(
header::LOCATION,
referer.with_server_fn(&e).as_str(),
referer.with_server_fn(&e, fn_name.as_str()).as_str(),
)
.body(Default::default())
} else {
Expand Down
6 changes: 3 additions & 3 deletions integrations/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ pub fn referer_to_url(referer: &HeaderValue) -> Option<Url> {
}

pub trait WithServerFn {
fn with_server_fn(self, e: &ServerFnError) -> Self;
fn with_server_fn(self, e: &ServerFnError, path: &str) -> Self;
}

impl WithServerFn for Url {
fn with_server_fn(mut self, e: &ServerFnError) -> Self {
fn with_server_fn(mut self, e: &ServerFnError, path: &str) -> Self {
self.query_pairs_mut().append_pair(
"server_fn_error",
format!("server_fn_error_{path}").as_str(),
serde_qs::to_string(e)
.expect("Could not serialize server fn error!")
.as_str(),
Expand Down
2 changes: 1 addition & 1 deletion integrations/viz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async fn handle_server_fns_inner(
.status(StatusCode::SEE_OTHER)
.header(
header::LOCATION,
url.with_server_fn(&e).as_str(),
url.with_server_fn(&e, fn_name.as_str()).as_str(),
)
.body(Default::default())
} else {
Expand Down

0 comments on commit 554a593

Please sign in to comment.