mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
chore: clippy
This commit is contained in:
parent
11119144d2
commit
a42e371e79
5 changed files with 2 additions and 98 deletions
|
@ -1,47 +0,0 @@
|
||||||
use crate::errors::TodoAppError;
|
|
||||||
use leptos::prelude::*;
|
|
||||||
#[cfg(feature = "ssr")]
|
|
||||||
use leptos_axum::ResponseOptions;
|
|
||||||
|
|
||||||
// A basic function to display errors served by the error boundaries. Feel free to do more complicated things
|
|
||||||
// here than just displaying them
|
|
||||||
#[component]
|
|
||||||
pub fn ErrorTemplate(
|
|
||||||
#[prop(optional)] outside_errors: Option<Errors>,
|
|
||||||
#[prop(optional, into)] errors: Option<RwSignal<Errors>>,
|
|
||||||
) -> impl IntoView {
|
|
||||||
let errors = match outside_errors {
|
|
||||||
Some(e) => RwSignal::new(e),
|
|
||||||
None => match errors {
|
|
||||||
Some(e) => e,
|
|
||||||
None => panic!("No Errors found and we expected errors!"),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get Errors from Signal
|
|
||||||
// Downcast lets us take a type that implements `std::error::Error`
|
|
||||||
let errors =
|
|
||||||
move || errors.get().into_iter().map(|(_, v)| v).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
// Only the response code for the first error is actually sent from the server
|
|
||||||
// this may be customized by the specific application
|
|
||||||
/*#[cfg(feature = "ssr")]
|
|
||||||
{
|
|
||||||
let response = use_context::<ResponseOptions>();
|
|
||||||
if let Some(response) = response {
|
|
||||||
response.set_status(errors[0].status_code());
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<h1>"Errors"</h1>
|
|
||||||
{move || {
|
|
||||||
errors()
|
|
||||||
.into_iter()
|
|
||||||
.map(|error| {
|
|
||||||
view! { <p>"Error: " {error.to_string()}</p> }
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
use http::status::StatusCode;
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Error)]
|
|
||||||
pub enum TodoAppError {
|
|
||||||
#[error("Not Found")]
|
|
||||||
NotFound,
|
|
||||||
#[error("Internal Server Error")]
|
|
||||||
InternalServerError,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TodoAppError {
|
|
||||||
pub fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
|
||||||
TodoAppError::NotFound => StatusCode::NOT_FOUND,
|
|
||||||
TodoAppError::InternalServerError => {
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{app::shell, error_template::ErrorTemplate, errors::TodoAppError};
|
use crate::app::shell;
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::State,
|
extract::State,
|
||||||
|
@ -20,8 +20,6 @@ pub async fn file_and_error_handler(
|
||||||
if res.status() == StatusCode::OK {
|
if res.status() == StatusCode::OK {
|
||||||
res.into_response()
|
res.into_response()
|
||||||
} else {
|
} else {
|
||||||
let mut errors = Errors::default();
|
|
||||||
errors.insert_with_default_key(TodoAppError::NotFound);
|
|
||||||
let handler =
|
let handler =
|
||||||
leptos_axum::render_app_to_stream(move || shell(&options));
|
leptos_axum::render_app_to_stream(move || shell(&options));
|
||||||
handler(req).await.into_response()
|
handler(req).await.into_response()
|
||||||
|
|
|
@ -1,29 +1,10 @@
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod error_template;
|
|
||||||
pub mod errors;
|
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub mod fallback;
|
pub mod fallback;
|
||||||
|
|
||||||
#[cfg(feature = "hydrate")]
|
#[cfg(feature = "hydrate")]
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen]
|
#[wasm_bindgen::prelude::wasm_bindgen]
|
||||||
pub fn hydrate() {
|
pub fn hydrate() {
|
||||||
use crate::app::App;
|
|
||||||
/* use tracing_subscriber::fmt;
|
|
||||||
use tracing_subscriber_wasm::MakeConsoleWriter;
|
|
||||||
|
|
||||||
fmt()
|
|
||||||
.with_writer(
|
|
||||||
// To avoide trace events in the browser from showing their
|
|
||||||
// JS backtrace, which is very annoying, in my opinion
|
|
||||||
MakeConsoleWriter::default()
|
|
||||||
.map_trace_level_to(tracing::Level::DEBUG),
|
|
||||||
)
|
|
||||||
// For some reason, if we don't do this in the browser, we get
|
|
||||||
// a runtime error.
|
|
||||||
.without_time()
|
|
||||||
.init();
|
|
||||||
_ = console_log::init_with_level(log::Level::Error);*/
|
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
leptos::mount::hydrate_islands();
|
leptos::mount::hydrate_islands();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
use crate::{app::*, fallback::file_and_error_handler};
|
use crate::{app::*, fallback::file_and_error_handler};
|
||||||
use axum::{
|
use axum::Router;
|
||||||
body::Body,
|
|
||||||
extract::{Path, State},
|
|
||||||
http::Request,
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
routing::get,
|
|
||||||
Router,
|
|
||||||
};
|
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||||
use todo_app_sqlite_axum::*;
|
use todo_app_sqlite_axum::*;
|
||||||
|
|
Loading…
Reference in a new issue