#[derive(RpcError)]
{
// Attributes available to this derive:
#[rpc]
}
Expand description
Derive macro for RPC errors
Generates From<YourError> for ServiceError and IntoServiceError implementations.
Use #[rpc(status = "...", code = ...)] attributes on variants to customize
the RPC status and error code.
§Example
ⓘ
use synapse_macros::RpcError;
#[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,
}§Available statuses
Ok- SuccessError- Generic error (default)Timeout- Request timed outInterfaceNotFound- Interface not foundMethodNotFound- Method not foundUnavailable- Service unavailableInvalidRequest- Bad requestUnsupportedVersion- Unsupported protocol versionServiceDraining- Service is drainingServiceFrozen- Service is frozenMessageTooLarge- Message too large