chatgpt/
err.rs

1use std::{env::VarError, string::FromUtf8Error};
2
3use reqwest::header::InvalidHeaderValue;
4use thiserror::Error;
5
6/// An error enum, used in the Result
7#[derive(Debug, Error)]
8pub enum Error {
9    /// A reqwest-provoked error has occurred
10    #[error("An error occurred when processing a request: {0}")]
11    ClientError(#[from] reqwest::Error),
12    /// Invalid header configuration error. Probably because of the custom User-Agent header
13    #[error("Invalid configuration provided: {0}")]
14    InvalidConfiguration(#[from] InvalidHeaderValue),
15    /// An error that occurred when parsing data, e.g. a UUID
16    #[error("Parsing error has occurred: {0}")]
17    ParsingError(String),
18    /// A serde-provoked JSON error has occurred
19    #[cfg(any(feature = "json", feature = "functions"))]
20    #[error("Failed to (de)serialize data: {0}")]
21    SerdeJsonError(#[from] serde_json::Error),
22    /// A postcard-provoked error has occurred
23    #[error("Failed to (de)serialize data: {0}")]
24    #[cfg(feature = "postcard")]
25    PostcardError(#[from] postcard::Error),
26    /// An error has occurred when parsing a string from UTF-8 bytes
27    #[error("Failed to parse string from UTF-8: {0}")]
28    StringError(#[from] FromUtf8Error),
29    /// An error on the backend happened
30    #[error("An error (type: {error_type}) occurred on the API backend: {message}")]
31    BackendError {
32        /// Message, describing this error
33        message: String,
34        /// The type of error
35        error_type: String,
36    },
37    /// A Tokio IO error happened
38    #[error("Error happened during an IO operation: {0}")]
39    IOError(#[from] tokio::io::Error),
40    /// Most likely env var not provided
41    #[error("Error while trying to access an environment variable: {0}")]
42    VarError(#[from] VarError),
43}