Skip to content

What's the best method for handling SDK errors? #599

Answered by Velfi
rnhurt asked this question in Q&A
Discussion options

You must be logged in to vote

Errors in the Rust SDKs have a kind field that contains this information and we provide methods for checking this. Here's the docs for CreateLogStreamError.

With this in mind, your code could look like this:

    match client
        .create_log_stream()
        .log_group_name("/my/group/name")
        .log_stream_name("my_test_stream")
        .send()
        .await
    {
        Ok(_) => println!("Created new log stream."),
        Err(e) => {
            if e.is_resource_already_exists_exception() { println!("Log stream already exists") }
            else { panic!("Error creating log stream: {}", e) };
        }
    }

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@rnhurt
Comment options

@Velfi
Comment options

@rnhurt
Comment options

@ivan-kiselev
Comment options

Answer selected by rnhurt
Comment options

You must be logged in to vote
2 replies
@michaelrommel
Comment options

@Velfi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants