Skip to content

Commit

Permalink
Include missing route path in error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Mar 13, 2024
1 parent c1589b2 commit 0027436
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions crate/web_components/src/error_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ use leptos_axum::ResponseOptions;

#[derive(Clone, Debug, Error)]
pub enum AppError {
#[error("Route Not Found. Check that the site prefix is correctly set and routed to.")]
RouteNotFound,
#[error("Route Not Found: {path}. Check that the site prefix is correctly set and routed to.")]
RouteNotFound {
/// The path that isn't routed.
path: String,
},
}

impl AppError {
pub fn status_code(&self) -> StatusCode {
match self {
AppError::RouteNotFound => StatusCode::NOT_FOUND,
AppError::RouteNotFound { .. } => StatusCode::NOT_FOUND,
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions playground/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ pub fn App() -> impl IntoView {
// content for this welcome page
<Router
fallback=|| {
let route_context = leptos_router::use_route();

let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::RouteNotFound);
outside_errors.insert_with_default_key(AppError::RouteNotFound {
path: route_context.path(),
});
view! {
<ErrorTemplate outside_errors/>
}
Expand All @@ -68,7 +72,6 @@ pub fn App() -> impl IntoView {
>
<main>
<Routes>
<Route path="/" view=|| view! { <HomePage/> }/>
<Route path=site_prefix view=|| view! { <HomePage/> }/>
</Routes>
</main>
Expand Down

0 comments on commit 0027436

Please sign in to comment.