impl Error for MsgError
use crate::state_types::EnvError;
use crate::types::api::APIErr;
use serde::Serialize;
+use std::error::Error;
+use std::fmt;
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type", content = "args")]
@@ -9,6 +11,22 @@ pub enum MsgError {
Env { message: String },
}
+impl fmt::Display for MsgError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let message = match &self {
+ MsgError::API { message, .. } => message.to_owned(),
+ MsgError::Env { message } => message.to_owned(),
+ };
+ write!(f, "{}", message)
+ }
+}
+
+impl Error for MsgError {
+ fn description(&self) -> &str {
+ format!("{}", &self).as_str()
+ }
+}
+
impl From<APIErr> for MsgError {
fn from(error: APIErr) -> Self {
MsgError::API {
