Skip to content

Commit

Permalink
refactor(services/cloudflare-kv): remove unneeded async and result on…
Browse files Browse the repository at this point in the history
… parse_error (#5128)

* remove unneeded async and result on parse_error

* improve encapsulation
  • Loading branch information
tsfotis committed Sep 19, 2024
1 parent 465e17c commit da9a685
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions core/src/services/cloudflare_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl kv::Adapter for Adapter {
let status = resp.status();
match status {
StatusCode::OK => Ok(Some(resp.into_body())),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -222,7 +222,7 @@ impl kv::Adapter for Adapter {
let status = resp.status();
match status {
StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -236,7 +236,7 @@ impl kv::Adapter for Adapter {
let status = resp.status();
match status {
StatusCode::OK => Ok(()),
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}

Expand All @@ -263,18 +263,18 @@ impl kv::Adapter for Adapter {
})?;
Ok(response.result.into_iter().map(|r| r.name).collect())
}
_ => Err(parse_error(resp).await?),
_ => Err(parse_error(resp)),
}
}
}

#[derive(Debug, Deserialize)]
pub(crate) struct CfKvResponse {
pub(crate) errors: Vec<CfKvError>,
pub(super) struct CfKvResponse {
pub(super) errors: Vec<CfKvError>,
}

#[derive(Debug, Deserialize)]
pub(crate) struct CfKvScanResponse {
pub(super) struct CfKvScanResponse {
result: Vec<CfKvScanResult>,
// According to https://developers.cloudflare.com/api/operations/workers-kv-namespace-list-a-namespace'-s-keys, result_info is used to determine if there are more keys to be listed
// result_info: Option<CfKvResultInfo>,
Expand All @@ -292,8 +292,8 @@ struct CfKvScanResult {
// }

#[derive(Debug, Deserialize)]
pub(crate) struct CfKvError {
pub(crate) code: i32,
pub(super) struct CfKvError {
pub(super) code: i32,
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions core/src/services/cloudflare_kv/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::raw::*;
use crate::*;

/// Parse error response into Error.
pub(crate) async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());

Expand Down Expand Up @@ -59,10 +59,10 @@ pub(crate) async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
err = err.set_temporary();
}

Ok(err)
err
}

pub(crate) fn parse_cfkv_error_code(errors: Vec<CfKvError>) -> Option<(ErrorKind, bool)> {
pub(super) fn parse_cfkv_error_code(errors: Vec<CfKvError>) -> Option<(ErrorKind, bool)> {
if errors.is_empty() {
return None;
}
Expand Down

0 comments on commit da9a685

Please sign in to comment.