Skip to main content

sf_api/
error.rs

1use thiserror::Error;
2
3/// An error, that occurred during the communication (sending/receiving/parsing)
4/// of requests to the S&F server
5#[derive(Debug, Error)]
6#[non_exhaustive]
7#[allow(clippy::module_name_repetitions)]
8pub enum SFError {
9    /// Whatever you were trying to send was not possible to send. This is
10    /// either our issue when you were doing something normal, or you were
11    /// sending invalid stuff, like a SSO login on a normal logged in character
12    #[error("Tried to send an invalid request: {0}")]
13    InvalidRequest(&'static str),
14    /// The server replied with an empty response. This could have a range of
15    /// reasons. Could be a bad request, not logged in, or something else
16    #[error("Received an empty response from the server")]
17    EmptyResponse,
18    /// There was some error encountered when sending data to the server. Most
19    /// likely the server, or your connection is down
20    #[error("Could not communicate with the server")]
21    ConnectionError,
22    /// Whatever the server sent back was invalid. Could be because of features
23    /// not yet supported, or a bug in the API
24    #[error(
25        "Error parsing the server response because {0} had an unexpected \
26         value of: {1}"
27    )]
28    ParsingError(&'static str, String),
29    /// The server responded with an error. If you are already logged in, this
30    /// is likely recoverable,  i.e you are able to reuse your session. You
31    /// should just not resend the same command, as the server had some error
32    /// with it. Most likely that you were not allowed to do your action (spend
33    /// money you don't have, etc.)
34    #[error("Server responded with error: {0}")]
35    ServerError(String),
36    /// The server version is newer, than the limit set in the server
37    /// communication
38    #[error("The server version {0} is not supported")]
39    UnsupportedVersion(u32),
40    /// The server responded with a response, that was too short
41    #[error(
42        "Tried to access the response for {name} at [{pos}] , but the \
43         response is too short. The response is: {array}"
44    )]
45    TooShortResponse {
46        /// The name of the item, that was accessed
47        name: &'static str,
48        /// The position at which the array access failed
49        pos: usize,
50        /// The full array in debug print
51        array: String,
52    },
53    /// Multiple errors occured when parsing the response
54    #[error("Multiple errors occurred:\n{}", .0.iter().map(|e| format!("  - {e}")).collect::<Vec<_>>().join("\n"))]
55    NestedError(Vec<SFError>),
56}