From 2f73b9aea98893978b61ffeae747f451970c63f8 Mon Sep 17 00:00:00 2001 From: George Shipilov Date: Fri, 30 Aug 2024 10:53:25 -0400 Subject: [PATCH] add From impl for GrpcCode Fixes: #505 --- .../src/classify/grpc_errors_as_failures.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tower-http/src/classify/grpc_errors_as_failures.rs b/tower-http/src/classify/grpc_errors_as_failures.rs index b88606b5..c24346fb 100644 --- a/tower-http/src/classify/grpc_errors_as_failures.rs +++ b/tower-http/src/classify/grpc_errors_as_failures.rs @@ -70,6 +70,32 @@ impl GrpcCode { } } +impl From for GrpcCode { + fn from(value: i32) -> Self { + match value { + 0 => GrpcCode::Ok, + 1 => GrpcCode::Cancelled, + 2 => GrpcCode::Unknown, + 3 => GrpcCode::InvalidArgument, + 4 => GrpcCode::DeadlineExceeded, + 5 => GrpcCode::NotFound, + 6 => GrpcCode::AlreadyExists, + 7 => GrpcCode::PermissionDenied, + 8 => GrpcCode::ResourceExhausted, + 9 => GrpcCode::FailedPrecondition, + 10 => GrpcCode::Aborted, + 11 => GrpcCode::OutOfRange, + 12 => GrpcCode::Unimplemented, + 13 => GrpcCode::Internal, + 14 => GrpcCode::Unavailable, + 15 => GrpcCode::DataLoss, + 16 => GrpcCode::Unauthenticated, + + _ => GrpcCode::Unknown, + } + } +} + bitflags! { #[derive(Debug, Clone, Copy)] pub(crate) struct GrpcCodeBitmask: u32 {