diff --git a/src/http/client.rs b/src/http/client.rs index de7ff11..3676fa8 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -30,7 +30,7 @@ impl Client { let wasi_body = wasi_req.body().unwrap(); // 1. Start sending the request head - let res = wasip2::http::outgoing_handler::handle(wasi_req, self.wasi_options()?).unwrap(); + let res = wasip2::http::outgoing_handler::handle(wasi_req, self.wasi_options()?)?; let ((), body) = futures_lite::future::try_zip( async move { diff --git a/tests/http_handle_error_code.rs b/tests/http_handle_error_code.rs new file mode 100644 index 0000000..6affb90 --- /dev/null +++ b/tests/http_handle_error_code.rs @@ -0,0 +1,21 @@ +use wstd::http::{Body, Client, Request, error::ErrorCode}; + +/// Test that `outgoing_handler::handle` errors are properly propagated. +#[wstd::test] +async fn handle_returns_error_code() -> Result<(), Box> { + let request = Request::get("ftp://example.com/").body(Body::empty())?; + + let result = Client::new().send(request).await; + + assert!( + result.is_err(), + "request with unsupported scheme should fail" + ); + let error = result.unwrap_err(); + assert!( + error.downcast_ref::().is_some(), + "expected an ErrorCode, got: {error:?}" + ); + + Ok(()) +}