From 81d6689cc0c659d2e9ba056dbf581dc9b033db10 Mon Sep 17 00:00:00 2001 From: IcosaHedron <110272232+Indrazar@users.noreply.github.com> Date: Sun, 12 Feb 2023 21:59:12 -0500 Subject: [PATCH] do not unwrap use_context in integrations axum redirect (#513) --- integrations/axum/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index f86c5c1..1d21f05 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -94,13 +94,14 @@ impl ResponseOptions { /// it sets a StatusCode of 302 and a LOCATION header with the provided value. /// If looking to redirect from the client, `leptos_router::use_navigate()` should be used instead pub fn redirect(cx: leptos::Scope, path: &str) { - let response_options = use_context::(cx).unwrap(); - response_options.set_status(StatusCode::FOUND); - response_options.insert_header( - header::LOCATION, - header::HeaderValue::from_str(path) - .expect("Failed to create HeaderValue"), - ); + if let Some(response_options) = use_context::(cx) { + response_options.set_status(StatusCode::FOUND); + response_options.insert_header( + header::LOCATION, + header::HeaderValue::from_str(path) + .expect("Failed to create HeaderValue"), + ); + } } /// Decomposes an HTTP request into its parts, allowing you to read its headers