1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Custom error types

use reqwest::Error;
use thiserror::Error;

/// Represents an error that was returned by a Steam API endpoint.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum SteamError {
    /// A reqwest failed for some reason
    #[error("Error response from steam: {0}")]
    FailedRequest(String),
    /// The requested data is either private, or not present at all. Usually, this comes from a
    /// deserialization error in serde.
    #[error("The data you requested is either private or empty")]
    NoData,
}

impl From<reqwest::Error> for SteamError {
    fn from(err: Error) -> Self {
        // If the reqwest goes wrong, we should forward it to the user
        let reqwest_error = err.to_string();
        Self::FailedRequest(reqwest_error)
    }
}