Skip to content

Commit

Permalink
fix error and add error handle for example
Browse files Browse the repository at this point in the history
  • Loading branch information
foxzool committed Apr 23, 2024
1 parent 67f7ba0 commit e00fd9b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 7 additions & 1 deletion examples/ipinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_http_client::prelude::*;
fn main() {
App::new()
.add_plugins((MinimalPlugins, HttpClientPlugin))
.add_systems(Update, handle_response)
.add_systems(Update, (handle_response, handle_error))
.add_systems(
Update,
send_request.run_if(on_timer(std::time::Duration::from_secs(1))),
Expand All @@ -22,3 +22,9 @@ fn handle_response(mut ev_resp: EventReader<HttpResponse>) {
println!("response: {:?}", response.text());
}
}

fn handle_error(mut ev_error: EventReader<HttpResponseError>) {
for error in ev_error.read() {
println!("Error retrieving IP: {}", error.err);
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ fn handle_request(
world.entity_mut(entity).despawn_recursive();
}
});
println!("commands_queue: {:?}", command_queue);

tx.send(command_queue).unwrap();
})
.detach();
Expand Down
7 changes: 1 addition & 6 deletions src/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ where
inner: T,
}

impl<T> TypedResponse<T> {
/// Returns a reference to the inner data contained in the HTTP response.
pub fn get_inner(&self) -> &T {
&self.inner
}

impl<T: for<'a> serde::Deserialize<'a>> TypedResponse<T> {
/// Consumes the HTTP response and returns the inner data.
pub fn into_inner(self) -> T {
self.inner
Expand Down

0 comments on commit e00fd9b

Please sign in to comment.