Skip to content

Commit

Permalink
chore: remove a few unwrap calls
Browse files Browse the repository at this point in the history
  • Loading branch information
imor committed Oct 4, 2023
1 parent ab54506 commit 8f46ebd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 7 additions & 7 deletions wrappers/src/fdw/logflare_fdw/logflare_fdw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ use supabase_wrappers::prelude::*;

use super::{LogflareFdwError, LogflareFdwResult};

fn create_client(api_key: &str) -> ClientWithMiddleware {
fn create_client(api_key: &str) -> LogflareFdwResult<ClientWithMiddleware> {
let mut headers = HeaderMap::new();
let header_name = HeaderName::from_static("x-api-key");
let mut auth_value = HeaderValue::from_str(api_key).unwrap();
let mut auth_value = HeaderValue::from_str(api_key)?;
auth_value.set_sensitive(true);
headers.insert(header_name, auth_value);
let client = reqwest::Client::builder()
.default_headers(headers)
.build()
.unwrap();
.build()?;
let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
ClientBuilder::new(client)
Ok(ClientBuilder::new(client)
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
.build()
.build())
}

fn extract_params(quals: &[Qual]) -> Option<Vec<Qual>> {
Expand Down Expand Up @@ -205,7 +204,8 @@ impl ForeignDataWrapper<LogflareFdwError> for LogflareFdw {
let key_id = require_option("api_key_id", options)?;
get_vault_secret(key_id).map(|api_key| create_client(&api_key))
}
};
}
.transpose()?;

stats::inc_stats(Self::FDW_NAME, stats::Metric::CreateTimes, 1);

Expand Down
9 changes: 8 additions & 1 deletion wrappers/src/fdw/logflare_fdw/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::module_inception)]
mod logflare_fdw;

use http::header::InvalidHeaderValue;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::prelude::PgSqlErrorCode;
use thiserror::Error;
Expand Down Expand Up @@ -33,8 +34,14 @@ enum LogflareFdwError {
#[error("parse url failed: {0}")]
UrlParseError(#[from] url::ParseError),

#[error("invalid api_key header: {0}")]
InvalidApiKeyHeader(#[from] InvalidHeaderValue),

#[error("request failed: {0}")]
RequestError(#[from] reqwest_middleware::Error),
RequestError(#[from] reqwest::Error),

#[error("request middleware failed: {0}")]
RequestMiddlewareError(#[from] reqwest_middleware::Error),

#[error("parse JSON response failed: {0}")]
JsonParseError(#[from] serde_json::Error),
Expand Down

0 comments on commit 8f46ebd

Please sign in to comment.