Struct aws_smithy_types::error::Builder
source · pub struct Builder { /* private fields */ }
Expand description
Builder for Error
.
Implementations§
source§impl Builder
impl Builder
sourcepub fn request_id(&mut self, request_id: impl Into<String>) -> &mut Self
pub fn request_id(&mut self, request_id: impl Into<String>) -> &mut Self
Sets the request ID the error happened for.
sourcepub fn custom(&mut self, key: &'static str, value: impl Into<String>) -> &mut Self
pub fn custom(&mut self, key: &'static str, value: impl Into<String>) -> &mut Self
Set a custom field on the error metadata
Typically, these will be accessed with an extension trait:
use aws_smithy_types::Error;
const HOST_ID: &str = "host_id";
trait S3ErrorExt {
fn extended_request_id(&self) -> Option<&str>;
}
impl S3ErrorExt for Error {
fn extended_request_id(&self) -> Option<&str> {
self.extra(HOST_ID)
}
}
fn main() {
// Extension trait must be brought into scope
use S3ErrorExt;
let sdk_response: Result<(), Error> = Err(Error::builder().custom(HOST_ID, "x-1234").build());
if let Err(err) = sdk_response {
println!("request id: {:?}, extended request id: {:?}", err.request_id(), err.extended_request_id());
}
}