From 15b580c65dffee4e16e4d50c83d9da11e246e92d Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 17 Jan 2025 12:10:02 +0100 Subject: [PATCH] Slightly simpler error messages --- src/frontend/api.rs | 11 +++++------ src/frontend/error.rs | 21 --------------------- 2 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 src/frontend/error.rs diff --git a/src/frontend/api.rs b/src/frontend/api.rs index 7986188..9b05f85 100644 --- a/src/frontend/api.rs +++ b/src/frontend/api.rs @@ -9,6 +9,7 @@ use crate::common::{ use http::{Method, StatusCode}; use leptos::{prelude::ServerFnError, server_fn::error::NoCustomError}; use log::error; +use log::info; use serde::{Deserialize, Serialize}; use std::{fmt::Debug, sync::LazyLock}; use url::Url; @@ -353,16 +354,14 @@ impl ApiClient { T: for<'de> Deserialize<'de>, { let json = serde_json::from_str(&text).map_err(|e| { - ServerFnError::::Deserialization(format!( - "Serde error: {e} from {text} on {url}" - )) + info!("Failed to deserialize api response: {e} from {text} on {url}"); + ServerFnError::::Deserialization(text.clone()) })?; if status == StatusCode::OK { Ok(json) } else { - Err(ServerFnError::Response(format!( - "API error: {text} on {url} status {status}" - ))) + info!("API error: {text} on {url} status {status}"); + Err(ServerFnError::Response(text)) } } diff --git a/src/frontend/error.rs b/src/frontend/error.rs deleted file mode 100644 index cda634f..0000000 --- a/src/frontend/error.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::fmt::{Display, Formatter}; - -pub type MyResult = Result; - -#[derive(Debug)] -pub struct Error(pub anyhow::Error); - -impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(&self.0, f) - } -} - -impl From for Error -where - T: Into, -{ - fn from(t: T) -> Self { - Error(t.into()) - } -}