Skip to main content

Module error

Module error 

Source
Expand description

RPC error types for service handlers

Services define their own error types using thiserror, then implement Into<ServiceError> (or derive it with #[derive(RpcError)]).

§Example

use synapse_rpc::{RpcError, ServiceError};
use synapse_proto::RpcStatus;

#[derive(Debug, thiserror::Error, RpcError)]
pub enum UserError {
    #[error("user not found: {0}")]
    #[rpc(status = "Error", code = 404)]
    NotFound(String),

    #[error("invalid email format")]
    #[rpc(status = "InvalidRequest", code = 400)]
    InvalidEmail,

    #[error("user is banned")]
    #[rpc(code = 3001)]  // defaults to Error status
    Banned,
}

Structs§

ServiceError
Error type that maps to RPC response errors

Enums§

TransportError
Transport-level RPC error (codec, connection, etc.)

Traits§

IntoServiceError
Trait for errors that can be converted to RPC errors

Type Aliases§

RpcResult
Result type for RPC handlers