feat: handle status codes

This commit is contained in:
Valerio Ageno
2024-06-15 12:30:20 +02:00
parent 70b4b9c28f
commit 26c0c2488d
3 changed files with 27 additions and 12 deletions
@@ -1,3 +1,4 @@
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use tuono_lib::{Props, Request, Response};
@@ -21,11 +22,14 @@ async fn get_pokemon(req: Request<'_>, fetch: reqwest::Client) -> Response {
let data = res.json::<Pokemon>().await.unwrap();
Response::Props(Props::new(data))
}
Err(_err) => Response::Props(Props::new(Pokemon {
name: "Nope".to_string(),
id: 0,
weight: 0,
height: 0,
})),
Err(_err) => Response::Props(Props::new_with_status(
Pokemon {
name: "Nope".to_string(),
id: 0,
weight: 0,
height: 0,
},
StatusCode::INTERNAL_SERVER_ERROR,
)),
};
}