Skip to content

Commit

Permalink
backoff incase of unknown error (#35)
Browse files Browse the repository at this point in the history
* backoff incase of unknown error

* update log to print error

* tidy up error log
  • Loading branch information
Jayko001 authored May 30, 2024
1 parent 9132b59 commit 65f6d7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
supabase-wrappers = { git = "/~https://github.com/supabase/wrappers.git", default-features = false }
tokio = { version = "1", features = ["full"] }
reqwest = "0.11"

[dev-dependencies]
pgrx-tests = "=0.11.3"
21 changes: 7 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use supabase_wrappers::prelude::*;
pgrx::pg_module_magic!();

use clerk_rs::{
apis::organization_memberships_api::ListOrganizationMembershipsError,
apis::organization_memberships_api::OrganizationMembership,
apis::organizations_api::Organization, apis::users_api::User, clerk::Clerk, ClerkConfiguration,
};
Expand Down Expand Up @@ -248,21 +249,13 @@ impl ForeignDataWrapper<ClerkFdwError> for ClerkFdw {
)
.await
.map_err(|e| match e {
clerk_rs::apis::Error::Reqwest(ref reqwest_error) => {
if let Some(status_code) = reqwest_error.status() {
match status_code {
reqwest::StatusCode::TOO_MANY_REQUESTS |
reqwest::StatusCode::BAD_GATEWAY |
reqwest::StatusCode::SERVICE_UNAVAILABLE |
reqwest::StatusCode::GATEWAY_TIMEOUT |
reqwest::StatusCode::INTERNAL_SERVER_ERROR => {
info!("clerk_fdw: received {} error, backing off", status_code);
backoff::Error::transient(e)
},
_ => backoff::Error::Permanent(e),
clerk_rs::apis::Error::ResponseError(ref response_error) => {
match response_error.entity {
Some(ListOrganizationMembershipsError::UnknownValue(_)) => {
info!("clerk_fdw: received {:#?}, backing off", response_error.content);
backoff::Error::transient(e)
}
} else {
backoff::Error::Permanent(e)
_ => backoff::Error::Permanent(e),
}
}
_ => backoff::Error::Permanent(e),
Expand Down

0 comments on commit 65f6d7d

Please sign in to comment.