Skip to content

Commit

Permalink
minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Heulitig authored and amitu committed Mar 14, 2024
1 parent a9e6bfe commit 6ee6bc5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
10 changes: 2 additions & 8 deletions fastn-core/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions fastn-core/src/library2022/processor/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
})
};
Expand Down
4 changes: 2 additions & 2 deletions ftd/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = std::result::Result<T, Error>;
Expand Down
1 change: 0 additions & 1 deletion integration-tests/_tests/04-multi-endpoint-test.test.ftd
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 6ee6bc5

Please sign in to comment.