multi_rpc/error.rs
1use serde::Deserialize;
2use serde::Serialize;
3use thiserror::Error;
4
5/// A general-purpose error type for RPC service methods.
6///
7/// This enum is intended to be used within the `Result` returned by your service
8/// trait's methods, allowing business logic errors to be serialized and sent to the client.
9#[derive(Error, Debug, Serialize, Deserialize)]
10pub enum RpcError {
11 /// Represents an internal server error or a logic failure.
12 #[error("Internal server error: {0}")]
13 InternalError(String),
14}
15
16impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for RpcError {
17 fn from(err: Box<dyn std::error::Error + Send + Sync + 'static>) -> Self {
18 // Convert the error to its string representation and wrap it in our variant.
19 RpcError::InternalError(err.to_string())
20 }
21}