Skip to content

Commit

Permalink
Merge pull request #150 from supabase/chore/stripe-fdw-error
Browse files Browse the repository at this point in the history
chore(stripe_fdw): refactor error reporting
  • Loading branch information
imor authored Sep 18, 2023
2 parents 07db254 + 3fb0974 commit 5d495f1
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 186 deletions.
4 changes: 2 additions & 2 deletions wrappers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pg_test = []
helloworld_fdw = []
bigquery_fdw = ["gcp-bigquery-client", "serde_json", "serde", "wiremock", "futures", "yup-oauth2", "thiserror"]
clickhouse_fdw = ["clickhouse-rs", "chrono", "chrono-tz", "regex", "thiserror"]
stripe_fdw = ["reqwest", "reqwest-middleware", "reqwest-retry", "serde_json", "thiserror"]
stripe_fdw = ["reqwest", "reqwest-middleware", "reqwest-retry", "serde_json", "thiserror", "url"]
firebase_fdw = ["reqwest", "reqwest-middleware", "reqwest-retry", "serde_json", "yup-oauth2", "regex", "thiserror"]
s3_fdw = [
"reqwest", "reqwest-middleware", "reqwest-retry", "aws-config", "aws-sdk-s3",
Expand Down Expand Up @@ -58,7 +58,7 @@ reqwest-retry = { version = "0.2.2", optional = true }
yup-oauth2 = { version = "8.0.0", optional = true }
regex = { version = "1", optional = true }

# for airtable_fdw
# for airtable_fdw, stripe_fdw
url = { version = "2.3", optional = true }

# for s3_fdw
Expand Down
38 changes: 38 additions & 0 deletions wrappers/src/fdw/stripe_fdw/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
#![allow(clippy::module_inception)]
mod stripe_fdw;
mod tests;

use pgrx::pg_sys::panic::ErrorReport;
use pgrx::prelude::PgSqlErrorCode;
use thiserror::Error;

use supabase_wrappers::prelude::{CreateRuntimeError, OptionsError};

#[derive(Error, Debug)]
enum StripeFdwError {
#[error("column '{0}' data type is not supported")]
UnsupportedColumnType(String),

#[error("Stripe object '{0}' not implemented")]
ObjectNotImplemented(String),

#[error("{0}")]
OptionsError(#[from] OptionsError),

#[error("{0}")]
CreateRuntimeError(#[from] CreateRuntimeError),

#[error("parse url failed: {0}")]
UrlParseError(#[from] url::ParseError),

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

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

impl From<StripeFdwError> for ErrorReport {
fn from(value: StripeFdwError) -> Self {
ErrorReport::new(PgSqlErrorCode::ERRCODE_FDW_ERROR, format!("{value}"), "")
}
}

type StripeFdwResult<T> = Result<T, StripeFdwError>;
Loading

0 comments on commit 5d495f1

Please sign in to comment.