Skip to content

Commit

Permalink
feat: Expose status constructors (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Dyas committed Apr 7, 2021
1 parent 480a794 commit 0d05aa0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ impl Status {
Status::from_error(&*err.into())
}

pub(crate) fn from_header_map(header_map: &HeaderMap) -> Option<Status> {
/// Extract a `Status` from a hyper `HeaderMap`.
pub fn from_header_map(header_map: &HeaderMap) -> Option<Status> {
header_map.get(GRPC_STATUS_HEADER_CODE).map(|code| {
let code = Code::from_bytes(code.as_ref());
let error_message = header_map
Expand Down Expand Up @@ -661,7 +662,10 @@ impl Code {
Code::from(i)
}

pub(crate) fn from_bytes(bytes: &[u8]) -> Code {
/// Convert the string representation of a `Code` (as stored, for example, in the `grpc-status`
/// header in a response) into a `Code`. Returns `Code::Unknown` if the code string is not a
/// valid gRPC status code.
pub fn from_bytes(bytes: &[u8]) -> Code {
match bytes.len() {
1 => match bytes[0] {
b'0' => Code::Ok,
Expand Down

0 comments on commit 0d05aa0

Please sign in to comment.