From 02ce89708224b28c29add26c379a248f510e7baa Mon Sep 17 00:00:00 2001 From: Tomas Olvecky Date: Sun, 15 Feb 2026 18:13:26 +0100 Subject: [PATCH 1/3] Allow catching `ErrorCode` from `outgoing_handler::handle` --- src/http/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From 019733f73ef957bd3b1c578870a0090d7382b260 Mon Sep 17 00:00:00 2001 From: Tomas Olvecky Date: Wed, 18 Feb 2026 11:11:09 +0000 Subject: [PATCH 2/3] Test `ErrorCode` handling --- tests/http_handle_error_code.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/http_handle_error_code.rs diff --git a/tests/http_handle_error_code.rs b/tests/http_handle_error_code.rs new file mode 100644 index 0000000..b614c28 --- /dev/null +++ b/tests/http_handle_error_code.rs @@ -0,0 +1,19 @@ +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(()) +} From 78f1a21666a4d75367e2ff36a2fc7565e0dcb35e Mon Sep 17 00:00:00 2001 From: Tomas Olvecky Date: Wed, 18 Feb 2026 12:59:06 +0100 Subject: [PATCH 3/3] Reformat test file --- tests/http_handle_error_code.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/http_handle_error_code.rs b/tests/http_handle_error_code.rs index b614c28..6affb90 100644 --- a/tests/http_handle_error_code.rs +++ b/tests/http_handle_error_code.rs @@ -3,12 +3,14 @@ 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 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"); + assert!( + result.is_err(), + "request with unsupported scheme should fail" + ); let error = result.unwrap_err(); assert!( error.downcast_ref::().is_some(),