1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! plugin error module implementation
use serde::Serialize;
use std::fmt;

#[derive(Debug, Clone, Serialize)]
pub struct PluginError {
    code: i32,
    #[serde(rename = "message")]
    mgs: String,
    data: Option<serde_json::Value>,
}

impl PluginError {
    #[allow(dead_code)]
    fn new(code: i32, msg: &str, data: &Option<serde_json::Value>) -> Self
    where
        Self: Sized,
    {
        return PluginError {
            code,
            mgs: msg.to_string(),
            data: data.to_owned(),
        };
    }
}

impl fmt::Display for PluginError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "code: {}, msg: {}", self.code, self.mgs,)
    }
}