Skip to content

Commit

Permalink
feat(flags): add experience continuity (#25245)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
dmarticus and github-actions[bot] authored Oct 2, 2024
1 parent b33cad6 commit 2117916
Show file tree
Hide file tree
Showing 14 changed files with 1,745 additions and 398 deletions.
79 changes: 79 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/feature-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ strum = { version = "0.26", features = ["derive"] }
health = { path = "../common/health" }
common-metrics = { path = "../common/metrics" }
tower = { workspace = true }
derive_builder = "0.20.1"

[lints]
workspace = true
Expand Down
22 changes: 20 additions & 2 deletions rust/feature-flags/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub enum FlagError {
NoTokenError,
#[error("API key is not valid")]
TokenValidationError,
#[error("Row not found in postgres")]
RowNotFound,
#[error("failed to parse redis cache data")]
DataParsingError,
#[error("failed to update redis cache")]
Expand All @@ -94,6 +96,8 @@ pub enum FlagError {
RedisUnavailable,
#[error("database unavailable")]
DatabaseUnavailable,
#[error("Database error: {0}")]
DatabaseError(String),
#[error("Timed out while fetching data")]
TimeoutError,
#[error("No group type mappings")]
Expand Down Expand Up @@ -162,6 +166,13 @@ impl IntoResponse for FlagError {
"Our database service is currently unavailable. This is likely a temporary issue. Please try again later.".to_string(),
)
}
FlagError::DatabaseError(msg) => {
tracing::error!("Database error: {}", msg);
(
StatusCode::INTERNAL_SERVER_ERROR,
"A database error occurred. Please try again later or contact support if the problem persists.".to_string(),
)
}
FlagError::TimeoutError => {
tracing::error!("Timeout error: {:?}", self);
(
Expand All @@ -176,6 +187,13 @@ impl IntoResponse for FlagError {
"No group type mappings found. This is likely a configuration issue. Please contact support.".to_string(),
)
}
FlagError::RowNotFound => {
tracing::error!("Row not found in postgres: {:?}", self);
(
StatusCode::INTERNAL_SERVER_ERROR,
"The requested row was not found in the database. Please try again later or contact support if the problem persists.".to_string(),
)
}
}
.into_response()
}
Expand Down Expand Up @@ -216,8 +234,8 @@ impl From<sqlx::Error> for FlagError {
tracing::error!("sqlx error: {}", e);
println!("sqlx error: {}", e);
match e {
sqlx::Error::RowNotFound => FlagError::TokenValidationError,
_ => FlagError::DatabaseUnavailable,
sqlx::Error::RowNotFound => FlagError::RowNotFound,
_ => FlagError::DatabaseError(e.to_string()),
}
}
}
4 changes: 2 additions & 2 deletions rust/feature-flags/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::Result;
use async_trait::async_trait;
use sqlx::{
pool::PoolConnection,
postgres::{PgPoolOptions, PgRow},
PgPool, Postgres,
postgres::{PgPool, PgPoolOptions, PgRow},
Postgres,
};
use thiserror::Error;
use tokio::time::timeout;
Expand Down
Loading

0 comments on commit 2117916

Please sign in to comment.