ddnet_account_client/
errors.rs

1use thiserror::Error;
2
3/// An error that is similar to
4/// common http errrors.
5/// Used for requests to the account
6/// server.
7#[derive(Error, Debug)]
8pub enum HttpLikeError {
9    /// The request failed.
10    #[error("The request failed to be sent.")]
11    Request,
12    /// Http-like status codes.
13    #[error("The server responsed with status code {0}")]
14    Status(u16),
15    /// Other errors
16    #[error("{0}")]
17    Other(anyhow::Error),
18}
19
20impl From<serde_json::Error> for HttpLikeError {
21    fn from(value: serde_json::Error) -> Self {
22        Self::Other(value.into())
23    }
24}
25
26/// An error that is similar to
27/// a file system error.
28#[derive(Error, Debug)]
29pub enum FsLikeError {
30    /// The request failed.
31    #[error("{0}")]
32    Fs(std::io::Error),
33    /// Other errors
34    #[error("{0}")]
35    Other(anyhow::Error),
36}
37
38impl From<std::io::Error> for FsLikeError {
39    fn from(value: std::io::Error) -> Self {
40        Self::Fs(value)
41    }
42}