cooplan_definition_consumer/
error.rs1use std::fmt;
2
3#[derive(Debug, Copy, Clone, PartialEq)]
4pub enum ErrorKind {
5 InternalFailure,
6 ExternalFailure,
7 AutoConfigFailure,
8 StateUpdateFailure,
9 AmqpFailure,
10 ApiFailure,
11}
12
13impl From<cooplan_auth::error::ErrorKind> for ErrorKind {
14 fn from(error_kind: cooplan_auth::error::ErrorKind) -> Self {
15 match error_kind {
16 _ => ErrorKind::InternalFailure,
17 }
18 }
19}
20
21#[derive(Debug, Clone, PartialEq)]
22pub struct Error {
23 pub kind: ErrorKind,
24 pub message: String,
25}
26
27impl Error {
28 pub fn new(kind: ErrorKind, message: impl Into<String>) -> Error {
29 Error {
30 kind,
31 message: message.into(),
32 }
33 }
34
35 pub fn kind(&self) -> ErrorKind {
36 self.kind
37 }
38}
39
40impl fmt::Display for Error {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 write!(f, "{}", self.message)
43 }
44}
45
46impl From<cooplan_auth::error::Error> for Error {
47 fn from(error: cooplan_auth::error::Error) -> Self {
48 let error_kind: ErrorKind = error.kind().into();
49
50 Error {
51 kind: error_kind,
52 message: error.message,
53 }
54 }
55}