GrpcError

Derive Macro GrpcError 

Source
#[derive(GrpcError)]
{
    // Attributes available to this derive:
    #[grpc]
}
Available on crate feature router-grpc only.
Expand description

Re-export GrpcError derive macro for automatic tonic::Status conversion Derive macro for automatic gRPC status conversion

Generates From<Error> for tonic::Status implementation. Use #[grpc(CODE)] on variants to specify the gRPC status code.

§Example

use allframe_macros::GrpcError;
use thiserror::Error;

#[derive(Error, Debug, GrpcError)]
pub enum AppError {
    #[error("Unauthenticated: {0}")]
    #[grpc(UNAUTHENTICATED)]
    Unauthenticated(String),

    #[error("Rate limited")]
    #[grpc(RESOURCE_EXHAUSTED)]
    RateLimited,

    #[error("Not found: {0}")]
    #[grpc(NOT_FOUND)]
    NotFound(String),

    #[error("Internal error: {0}")]
    #[grpc(INTERNAL)]
    Internal(String),
}

// Auto-generates: impl From<AppError> for tonic::Status

§Supported gRPC Codes

  • OK, CANCELLED, UNKNOWN, INVALID_ARGUMENT
  • DEADLINE_EXCEEDED, NOT_FOUND, ALREADY_EXISTS
  • PERMISSION_DENIED, RESOURCE_EXHAUSTED, FAILED_PRECONDITION
  • ABORTED, OUT_OF_RANGE, UNIMPLEMENTED, INTERNAL
  • UNAVAILABLE, DATA_LOSS, UNAUTHENTICATED