From a5cb0e900aecc6d0dda033f8f461194c7cbb10c1 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Fri, 23 Aug 2024 13:53:53 +0200 Subject: [PATCH] Change where the HttpRequestDenied is returned Signed-off-by: Ryan Levick --- .../outbound-wasi-http-v0.2.0/src/lib.rs | 19 +++++++++++++++++-- .../test.json5 | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/components/outbound-wasi-http-v0.2.0/src/lib.rs b/components/outbound-wasi-http-v0.2.0/src/lib.rs index af6f572..d4dc399 100644 --- a/components/outbound-wasi-http-v0.2.0/src/lib.rs +++ b/components/outbound-wasi-http-v0.2.0/src/lib.rs @@ -51,14 +51,29 @@ impl bindings::Guest for Component { let response = match outgoing_handler::handle(outgoing_request, None) { Ok(r) => r, Err(e) => { - return_response(outparam, 500, e.to_string().as_bytes()); + return_response( + outparam, + 500, + format!("outgoing-handler/handle: {e}").as_bytes(), + ); return; } }; let response = loop { if let Some(response) = response.get() { - break response.unwrap().unwrap(); + let response = response.unwrap(); + match response { + Ok(r) => break r, + Err(e) => { + return_response( + outparam, + 500, + format!("incoming-response#get: {e}").as_bytes(), + ); + return; + } + }; } else { response.subscribe().block() } diff --git a/tests/outbound-wasi-http-v0.2.0-no-perms/test.json5 b/tests/outbound-wasi-http-v0.2.0-no-perms/test.json5 index d1df2f5..2b3fe7b 100644 --- a/tests/outbound-wasi-http-v0.2.0-no-perms/test.json5 +++ b/tests/outbound-wasi-http-v0.2.0-no-perms/test.json5 @@ -28,7 +28,7 @@ "optional": true } ], - "body": "ErrorCode::HttpRequestDenied" + "body": "incoming-response#get: ErrorCode::HttpRequestDenied" }, } ],