Skip to content

Commit 2f73b9a

Browse files
committed
add From<i32> impl for GrpcCode
Fixes: tower-rs#505
1 parent 3f98dc1 commit 2f73b9a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tower-http/src/classify/grpc_errors_as_failures.rs

+26
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ impl GrpcCode {
7070
}
7171
}
7272

73+
impl From<i32> for GrpcCode {
74+
fn from(value: i32) -> Self {
75+
match value {
76+
0 => GrpcCode::Ok,
77+
1 => GrpcCode::Cancelled,
78+
2 => GrpcCode::Unknown,
79+
3 => GrpcCode::InvalidArgument,
80+
4 => GrpcCode::DeadlineExceeded,
81+
5 => GrpcCode::NotFound,
82+
6 => GrpcCode::AlreadyExists,
83+
7 => GrpcCode::PermissionDenied,
84+
8 => GrpcCode::ResourceExhausted,
85+
9 => GrpcCode::FailedPrecondition,
86+
10 => GrpcCode::Aborted,
87+
11 => GrpcCode::OutOfRange,
88+
12 => GrpcCode::Unimplemented,
89+
13 => GrpcCode::Internal,
90+
14 => GrpcCode::Unavailable,
91+
15 => GrpcCode::DataLoss,
92+
16 => GrpcCode::Unauthenticated,
93+
94+
_ => GrpcCode::Unknown,
95+
}
96+
}
97+
}
98+
7399
bitflags! {
74100
#[derive(Debug, Clone, Copy)]
75101
pub(crate) struct GrpcCodeBitmask: u32 {

0 commit comments

Comments
 (0)