From 6ee6bc59c105146d94e3ba9b50746f4142115fec Mon Sep 17 00:00:00 2001 From: heulitig Date: Thu, 14 Mar 2024 16:41:11 +0530 Subject: [PATCH] minor refactors --- fastn-core/src/http.rs | 10 ++-------- fastn-core/src/library2022/processor/http.rs | 4 ++-- ftd/src/interpreter/mod.rs | 4 ++-- .../_tests/04-multi-endpoint-test.test.ftd | 1 - 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/fastn-core/src/http.rs b/fastn-core/src/http.rs index 94ab836ec0..e2be9cad98 100644 --- a/fastn-core/src/http.rs +++ b/fastn-core/src/http.rs @@ -542,10 +542,7 @@ pub async fn http_post_with_cookie( http_request.set_ip(req_config.request.ip.clone()); http_request.set_body(actix_web::web::Bytes::copy_from_slice(body.as_bytes())); - let http_url = match url::Url::parse(url) { - Ok(url) => url, - Err(e) => return Err(e.into()), - }; + let http_url = url::Url::parse(url).map_err(|e| fastn_core::Error::DSHttpError(e.into()))?; let res = req_config .config .ds @@ -631,10 +628,7 @@ pub async fn http_get_with_cookie( http_request.set_cookies(req.cookies()); http_request.set_headers(headers); http_request.set_ip(req.ip.clone()); - let http_url = match url::Url::parse(url) { - Ok(url) => url, - Err(e) => return Err(e.into()), - }; + let http_url = url::Url::parse(url).map_err(|e| fastn_core::Error::DSHttpError(e.into()))?; let res = ds .http(http_url, &http_request, &Default::default(), false) .await diff --git a/fastn-core/src/library2022/processor/http.rs b/fastn-core/src/library2022/processor/http.rs index 48cd10d077..1ceae083ae 100644 --- a/fastn-core/src/library2022/processor/http.rs +++ b/fastn-core/src/library2022/processor/http.rs @@ -125,7 +125,7 @@ pub async fn process( format!("{{{}}}", body.join(",")).as_str(), ) .await - .map_err(|e| ftd::interpreter::Error::DSError { + .map_err(|e| ftd::interpreter::Error::DSHttpError { message: format!("{:?}", e), }) } else { @@ -137,7 +137,7 @@ pub async fn process( false, // disable cache ) .await - .map_err(|e| ftd::interpreter::Error::DSError { + .map_err(|e| ftd::interpreter::Error::DSHttpError { message: format!("{:?}", e), }) }; diff --git a/ftd/src/interpreter/mod.rs b/ftd/src/interpreter/mod.rs index 51ff94572a..2dc88e173b 100644 --- a/ftd/src/interpreter/mod.rs +++ b/ftd/src/interpreter/mod.rs @@ -107,8 +107,8 @@ pub enum Error { #[error("Invalid access: {message}, line_number: {line_number}")] InvalidAccessError { message: String, line_number: usize }, - #[error("DSError: {message}")] - DSError { message: String }, + #[error("ds:HttpError: {message}")] + DSHttpError { message: String }, } pub type Result = std::result::Result; diff --git a/integration-tests/_tests/04-multi-endpoint-test.test.ftd b/integration-tests/_tests/04-multi-endpoint-test.test.ftd index 6ca70c2169..d4675e1c88 100644 --- a/integration-tests/_tests/04-multi-endpoint-test.test.ftd +++ b/integration-tests/_tests/04-multi-endpoint-test.test.ftd @@ -13,7 +13,6 @@ fastn.assert.eq(fastn.http_response["data"], "Hello, World!"); ;; Mountpoint: /ftd/* -> Endpoint: http://fastn.com/ftd/* -- fastn.get: Fetching content from fastn.com url: /ftd/column/ -http-status: 200 -- fastn.get: Redirect to google url: /goo/