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
32
33
use serde::Serialize;
use std::fmt;
#[derive(Debug, Clone, Serialize)]
pub struct PluginError {
code: i32,
#[serde(rename = "message")]
msg: String,
data: Option<serde_json::Value>,
}
impl PluginError {
#[allow(dead_code)]
pub fn new(code: i32, msg: &str, data: Option<serde_json::Value>) -> Self
where
Self: Sized,
{
PluginError {
code,
msg: msg.to_string(),
data,
}
}
}
impl fmt::Display for PluginError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "code: {}, msg: {}", self.code, self.msg)
}
}