Skip to content

Commit f0fd2ad

Browse files
committed
Add error branching to sample program
1 parent 4677dcd commit f0fd2ad

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/sample/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use podcast_api::Error;
12
use serde_json::json;
23

34
#[tokio::main]
@@ -17,7 +18,7 @@ async fn main() {
1718
.await
1819
{
1920
Ok(response) => {
20-
println!("Successfully called \"typeahead\" endpoint.");
21+
println!("Successfully called Listen Notes API.");
2122
if let Ok(body) = response.json().await {
2223
println!("Response Body:");
2324
println!("{}", body);
@@ -26,8 +27,16 @@ async fn main() {
2627
}
2728
}
2829
Err(err) => {
29-
println!("Error calling \"typeahead\" endpoint:");
30-
println!("{},", err);
30+
match err {
31+
Error::NotFoundError => { println!("Not Found: {}", err); }
32+
Error::AuthenticationError => { println!("Authentication Issue: {}", err); }
33+
Error::RateLimitError => { println!("Rate Limit: {}", err); }
34+
Error::InvalidRequestError => { println!("Invalid Request: {}", err); }
35+
Error::ListenApiError => { println!("API Error: {}", err); }
36+
Error::ApiConnectionError => { println!("Connection Issue: {}", err); }
37+
Error::Reqwest(err) => { println!("Reqwest HTTP Client Error: {}", err); }
38+
Error::Json(err) => { println!("JSON Parsing Error: {}", err); }
39+
}
3140
}
3241
};
3342
}

0 commit comments

Comments
 (0)