aboutsummaryrefslogtreecommitdiff
path: root/src/metadata.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/metadata.rs')
-rw-r--r--src/metadata.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/metadata.rs b/src/metadata.rs
index 893f6e2..caaebc8 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -7,6 +7,8 @@ use std::{mem, slice, str};
use crate::error::{Error, Result};
+const BINARY_ERROR_DETAILS_KEY: &str = "grpc-status-details-bin";
+
fn normalize_key(key: &str, binary: bool) -> Result<Cow<'_, str>> {
if key.is_empty() {
return Err(Error::InvalidMetadata(
@@ -107,6 +109,13 @@ impl MetadataBuilder {
Ok(self.add_metadata(&key, value))
}
+ /// Set binary error details to support rich error model.
+ ///
+ /// See also https://grpc.io/docs/guides/error/#richer-error-model.
+ pub(crate) fn set_binary_error_details(&mut self, value: &[u8]) -> &mut MetadataBuilder {
+ self.add_metadata(BINARY_ERROR_DETAILS_KEY, value)
+ }
+
/// Create `Metadata` with configured entries.
pub fn build(mut self) -> Metadata {
unsafe {
@@ -214,6 +223,16 @@ impl Metadata {
metadata: p,
})
}
+
+ /// Search for binary error details.
+ pub(crate) fn search_binary_error_details(&self) -> &[u8] {
+ for (k, v) in self.iter() {
+ if k == BINARY_ERROR_DETAILS_KEY {
+ return v;
+ }
+ }
+ &[]
+ }
}
impl Clone for Metadata {