From b0fd020d6ff6c9080964cbfbfdf23e3679de2b22 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Fri, 5 Aug 2022 05:02:49 +0000 Subject: [PATCH] server error is changed --- Cargo.toml | 2 +- src/error/rpc.rs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a7523ed..934711c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ serde = { version = "1", features = ["derive"] } serde_json = { version = "1" } prost = { version = "0" } -beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.21-snapshot" } +beteran-protobuf-rust = { git = "https://gitlab.loafle.net/bet/beteran-protobuf-rust.git", tag = "v0.1.22-snapshot" } [build-dependencies] diff --git a/src/error/rpc.rs b/src/error/rpc.rs index b8bca06..32b006b 100644 --- a/src/error/rpc.rs +++ b/src/error/rpc.rs @@ -194,7 +194,9 @@ impl fmt::Display for Internal { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Server { + pub code: i32, pub message: String, + pub data: Option>, } impl fmt::Display for Server { @@ -246,29 +248,29 @@ impl From for bpr::protobuf::rpc::Error { fn from(err: Error) -> Self { match err { Error::Parse(e) => bpr::protobuf::rpc::Error { - code: -32700, + code: bpr::protobuf::rpc::Error::PARSE, message: e.message, data: None, }, Error::InvalidRequest(e) => bpr::protobuf::rpc::Error { - code: -32600, + code: bpr::protobuf::rpc::Error::INVALID_REQUEST, message: e.message, data: None, }, Error::InvalidParams(e) => bpr::protobuf::rpc::Error { - code: -32602, + code: bpr::protobuf::rpc::Error::INVALID_PARAMS, message: e.message.clone(), data: Some(bpr::protobuf::rpc::InvalidParamsDetail::from(&e.detail).encode_to_vec()), }, Error::Internal(e) => bpr::protobuf::rpc::Error { - code: -32603, + code: bpr::protobuf::rpc::Error::INTERNAL, message: e.message, data: None, }, Error::Server(e) => bpr::protobuf::rpc::Error { - code: -32603, + code: e.code, message: e.message, - data: None, + data: e.data, }, } }