mirror of
https://github.com/Nutomic/ibis.git
synced 2025-01-27 17:05:49 +00:00
Slightly simpler error messages
This commit is contained in:
parent
d095e86b90
commit
15b580c65d
2 changed files with 5 additions and 27 deletions
|
@ -9,6 +9,7 @@ use crate::common::{
|
||||||
use http::{Method, StatusCode};
|
use http::{Method, StatusCode};
|
||||||
use leptos::{prelude::ServerFnError, server_fn::error::NoCustomError};
|
use leptos::{prelude::ServerFnError, server_fn::error::NoCustomError};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Debug, sync::LazyLock};
|
use std::{fmt::Debug, sync::LazyLock};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -353,16 +354,14 @@ impl ApiClient {
|
||||||
T: for<'de> Deserialize<'de>,
|
T: for<'de> Deserialize<'de>,
|
||||||
{
|
{
|
||||||
let json = serde_json::from_str(&text).map_err(|e| {
|
let json = serde_json::from_str(&text).map_err(|e| {
|
||||||
ServerFnError::<NoCustomError>::Deserialization(format!(
|
info!("Failed to deserialize api response: {e} from {text} on {url}");
|
||||||
"Serde error: {e} from {text} on {url}"
|
ServerFnError::<NoCustomError>::Deserialization(text.clone())
|
||||||
))
|
|
||||||
})?;
|
})?;
|
||||||
if status == StatusCode::OK {
|
if status == StatusCode::OK {
|
||||||
Ok(json)
|
Ok(json)
|
||||||
} else {
|
} else {
|
||||||
Err(ServerFnError::Response(format!(
|
info!("API error: {text} on {url} status {status}");
|
||||||
"API error: {text} on {url} status {status}"
|
Err(ServerFnError::Response(text))
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
pub type MyResult<T> = Result<T, Error>;
|
|
||||||
|
|
||||||
#[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<T> From<T> for Error
|
|
||||||
where
|
|
||||||
T: Into<anyhow::Error>,
|
|
||||||
{
|
|
||||||
fn from(t: T) -> Self {
|
|
||||||
Error(t.into())
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue