From 959b2f307134e9cbadd75fe2f940f9982575e073 Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:51:47 -0500 Subject: [PATCH] style and handle more errors --- doordesk/app/src/error_template.rs | 52 ++++++++++++------------------ 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/doordesk/app/src/error_template.rs b/doordesk/app/src/error_template.rs index 686d398..875b23d 100644 --- a/doordesk/app/src/error_template.rs +++ b/doordesk/app/src/error_template.rs @@ -1,3 +1,5 @@ +use std::any::type_name; + use cfg_if::cfg_if; use http::status::StatusCode; use leptos::*; @@ -20,8 +22,6 @@ impl AppError { } } -// A basic function to display errors served by the error boundaries. -// Feel free to do more complicated things here than just displaying the error. #[component] pub fn ErrorTemplate( #[prop(optional)] outside_errors: Option, @@ -37,38 +37,26 @@ pub fn ErrorTemplate( // Get Errors from Signal let errors = errors.get_untracked(); - // Downcast lets us take a type that implements `std::error::Error` - let errors: Vec = errors - .into_iter() - .filter_map(|(_k, v)| v.downcast_ref::().cloned()) - .collect(); + let errors: Box<_> = errors.into_iter().filter_map(|(_k, v)| v.into()).collect(); println!("Errors: {errors:#?}"); - // Only the response code for the first error is actually sent from the server - // this may be customized by the specific application - cfg_if! { if #[cfg(feature="ssr")] { - let response = use_context::(); - if let Some(response) = response { - response.set_status(errors[0].status_code()); - } - }} - view! { -

{if errors.len() > 1 { "Errors" } else { "Error" }}

- {error_code.to_string()} -

"Error: " {error_string}

- } - } - /> +
+

+ {if errors.len() > 1 { "Errors!" } else { "Error!" }} +

+
+ +
    + {move || { + errors + .into_iter() + .map(|e: &_| view! {
  • {e.to_string()}
  • }) + .collect_view() + }} + +
+ +
} }