summaryrefslogtreecommitdiff
path: root/src/api/guzzle.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/guzzle.rs')
-rw-r--r--src/api/guzzle.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/api/guzzle.rs b/src/api/guzzle.rs
index a13243d..6d1e41b 100644
--- a/src/api/guzzle.rs
+++ b/src/api/guzzle.rs
@@ -1,4 +1,6 @@
use crate::api::REQWEST_CLIENT;
+use crate::Error;
+
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
@@ -9,22 +11,22 @@ struct GuzzleResponse {
const GUZZLE: &str = "https://api.mydadleft.me";
-pub async fn get_random_teawie() -> String {
- let endpoint = "get_random_teawie";
+pub async fn get_random_teawie() -> Result<String, Error> {
+ let endpoint = "/get_random_teawie";
+
let req = REQWEST_CLIENT
- .get(format!("{GUZZLE}/{endpoint}"))
+ .get(format!("{GUZZLE}{endpoint}"))
.build()
.unwrap();
- let resp = REQWEST_CLIENT.execute(req).await.unwrap(); // why did i have to own
- // this constant? i have
- // no idea!
- let err_msg = "couldn't get a teawie";
- match resp.status() {
- StatusCode::OK => match resp.json::<GuzzleResponse>().await {
- Ok(data) => data.url,
- Err(why) => format!("{} ({:?})", err_msg, why),
- },
- other => format!("{} ({:?})", err_msg, other),
+ let resp = REQWEST_CLIENT.execute(req).await.unwrap();
+
+ if let StatusCode::OK = resp.status() {
+ match resp.json::<GuzzleResponse>().await {
+ Ok(data) => Ok(data.url),
+ Err(why) => Err(Box::new(why)),
+ }
+ } else {
+ Err(resp.status().to_string().into())
}
}