From 62c1937f116f26d419114747ff0ceb0f1d8e1f53 Mon Sep 17 00:00:00 2001 From: Franklin Date: Fri, 26 Aug 2022 22:49:44 -0400 Subject: [PATCH] Implemented display for erorr --- src/enums/error.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/enums/error.rs b/src/enums/error.rs index dceb251..8cbb5e8 100644 --- a/src/enums/error.rs +++ b/src/enums/error.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + #[derive(Debug)] pub enum Error { @@ -6,4 +8,16 @@ pub enum Error { UnexpectedStatusCode(u16, u16, String), NetworkError(String), SerdeError +} + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::CommunicatorError(message) => write!(f, "Error of type Communicator Error. Message: {}", message), + Error::UknownError => write!(f, "Error of type Uknown Error."), + Error::UnexpectedStatusCode(expected, actual, message) => write!(f, "Error of type UnexpectedStatusCode. Expected: {}, Actual: {}, Message: {}", expected, actual, message), + Error::NetworkError(message) => write!(f, "Error of type Network Error. Message: {}", message), + Error::SerdeError => write!(f, "Error of type Serde Error."), + } + } } \ No newline at end of file