Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose status constructors #579

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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