Skip to content

How can I make use of the generated_sdk::Error type? #693

Answered by jdisanti
skeet70 asked this question in Q&A
Discussion options

You must be logged in to vote

SdkError has an into_service_error() function that will convert it into the error type for the operation you called (for example, EncryptError for the Encrypt operation). Then the Error type at the crate root implements From for every one of these service error types.

So essentially, you can do something like this:

match call_kms_encrypt().await {
    Ok(success) => { /* do success stuff */ },
    Err(err) => aws_sdk_kms::Error::from(err.into_service_error())?,
}

Where your ApplicationError implements From<aws_sdk_kms::Error>. At that point, you're only dealing with conversion of one error type.

Edit: Actually, it's even simpler than that. aws_sdk_kms::Error already implements From<SdkError>

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
7 replies
@jdisanti
Comment options

@skeet70
Comment options

@jdisanti
Comment options

@skeet70
Comment options

@jdisanti
Comment options

Answer selected by Velfi
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants