rs_service_client/
error.rs1use std::error::Error;
3use std::fmt::{Display, Formatter};
4
5use crate::service::ServiceType;
6
7#[derive(Debug)]
8pub struct ServiceError {
9 pub service: ServiceType,
10 pub message: String,
11 pub status: String,
12}
13
14impl Display for ServiceError {
15 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16 write!(
17 f,
18 "Service error in service {}. Message: {} ({}).",
19 self.service, self.message, self.status
20 )
21 }
22}
23
24impl Error for ServiceError {}
25
26#[derive(Debug, Clone)]
27pub struct FetchError {
28 pub message: String,
29 pub url: String,
30}
31
32impl Display for FetchError {
33 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
34 write!(
35 f,
36 "Error fetching from {}. Message: {}.",
37 self.url, self.message
38 )
39 }
40}
41
42impl Error for FetchError {}
43
44#[derive(Debug)]
45pub struct MqttError {
46 pub message: String,
47}
48
49impl Display for MqttError {
50 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51 write!(f, "MQTT error: {}.", self.message,)
52 }
53}
54
55impl From<FetchError> for MqttError {
56 fn from(fetch_error: FetchError) -> Self {
57 MqttError {
58 message: fetch_error.message,
59 }
60 }
61}
62
63impl Error for MqttError {}
64
65#[derive(Debug)]
66pub struct SparkplugError {
67 pub message: String,
68}
69
70impl Display for SparkplugError {
71 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
72 write!(f, "{}", self.message)
73 }
74}
75
76impl Error for SparkplugError {}