Skip to content

Macro-based error handling for Tonic

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

vaultie/tonic-derive-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tonic-derive-error

A macro-based utility that simplifies Tonic error handling.

Example

use thiserror::Error;
use tonic::Code;
use tonic_derive_error::GrpcError;

#[derive(Error, GrpcError, Debug)]
pub enum CustomError {
    #[error("something went wrong")]
    #[grpc_error(status = "Code::FailedPrecondition")]
    ErrorVariant
}

GrpcError derive automatically generates the From<CustomError> for tonic::Status trait implementation.

When debug assertions are disabled (e.g. in release builds) errors with the Code::Internal status code are not displayed in a response and instead are logged using the tracing crate.

License

Licensed under either of Apache License 2.0 or MIT.

About

Macro-based error handling for Tonic

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published