feat: handle 404 on tutorial

This commit is contained in:
Valerio Ageno
2024-06-15 14:04:08 +02:00
parent 792358ea9c
commit 0be0ce4c15
2 changed files with 6 additions and 7 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ async fn get_all_pokemons(_req: Request<'_>, fetch: reqwest::Client) -> Response
Response::Props(Props::new(data))
}
Err(_err) => Response::Props(Props::new_with_status(
Pokemons { results: vec![] },
"{}", // Return empty JSON
StatusCode::INTERNAL_SERVER_ERROR,
)),
};
@@ -19,16 +19,15 @@ async fn get_pokemon(req: Request<'_>, fetch: reqwest::Client) -> Response {
return match fetch.get(format!("{POKEMON_API}/{pokemon}")).send().await {
Ok(res) => {
if res.status() == StatusCode::NOT_FOUND {
return Response::Props(Props::new_with_status("{}", StatusCode::NOT_FOUND));
}
let data = res.json::<Pokemon>().await.unwrap();
Response::Props(Props::new(data))
}
Err(_err) => Response::Props(Props::new_with_status(
Pokemon {
name: "Nope".to_string(),
id: 0,
weight: 0,
height: 0,
},
"{}",
StatusCode::INTERNAL_SERVER_ERROR,
)),
};