steamkit/steam/steam_client/
async_job_failed_exception.rs1use std::error::Error;
5use std::fmt;
6
7use crate::error::SteamError;
8
9#[derive(Debug)]
11pub struct AsyncJobFailedException {
12 message: String,
13 source: Option<Box<dyn Error + Send + Sync>>,
14}
15
16impl AsyncJobFailedException {
17 pub fn new() -> Self {
19 Self {
20 message: "The job failed remotely.".to_owned(),
21 source: None,
22 }
23 }
24
25 pub fn with_message(message: impl Into<String>) -> Self {
27 Self {
28 message: message.into(),
29 source: None,
30 }
31 }
32
33 pub fn with_cause(message: impl Into<String>, cause: impl Into<Box<dyn Error + Send + Sync>>) -> Self {
35 Self {
36 message: message.into(),
37 source: Some(cause.into()),
38 }
39 }
40
41 pub fn message(&self) -> &str {
43 &self.message
44 }
45}
46
47impl Default for AsyncJobFailedException {
48 fn default() -> Self {
49 Self::new()
50 }
51}
52
53impl fmt::Display for AsyncJobFailedException {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 match &self.source {
56 Some(source) => write!(f, "{}: {}", self.message, source),
57 None => f.write_str(&self.message),
58 }
59 }
60}
61
62impl Error for AsyncJobFailedException {
63 fn source(&self) -> Option<&(dyn Error + 'static)> {
64 self.source
65 .as_ref()
66 .map(|source| source.as_ref() as &(dyn Error + 'static))
67 }
68}
69
70impl From<AsyncJobFailedException> for SteamError {
71 fn from(_: AsyncJobFailedException) -> Self {
72 SteamError::JobFailed
73 }
74}