Add error enum

This commit is contained in:
Xiretza 2024-02-02 15:26:44 +00:00
parent 057b952d11
commit 42d2f29bfc
3 changed files with 37 additions and 0 deletions

21
Cargo.lock generated
View file

@ -179,6 +179,7 @@ dependencies = [
"serde_json",
"serde_repr",
"strum_macros",
"thiserror",
"time",
]
@ -840,6 +841,26 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "thiserror"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.32"

View file

@ -12,3 +12,4 @@ strum_macros = { version = "0.26.1"}
time = { version = "0.3.32", features = ["serde", "serde-well-known"]}
serde_json = "1.0.113"
serde_repr = "0.1.18"
thiserror = "1.0.56"

View file

@ -1,6 +1,7 @@
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::net::IpAddr;
use thiserror::Error;
#[derive(Debug)]
pub struct ValueError(String);
@ -13,6 +14,20 @@ impl std::fmt::Display for ValueError {
impl std::error::Error for ValueError {}
#[derive(Debug, Error)]
pub enum Error {
#[error("unsupported API version {0}")]
UnsupportedApiVersion(u64),
#[error("invalid endpoint {0:?}")]
InvalidEndpoint(String),
#[error("request failed")]
Request(#[from] reqwest::Error),
#[error("decoding response body failed")]
Decode(#[from] serde_json::Error),
#[error("received error response {:?}: {}", .0.code, .0.reason)]
Response(Status),
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct FroniousResponse<T> {