Skip to content

Commit

Permalink
enh: adds fallback url for expired short codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypalmudaliyar24 committed Jul 1, 2024
1 parent 7b54bd5 commit fe19d2c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/url_shortner/src/domain/action/public_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ pub async fn redirect_to_url(
info!("redirecting to: {}", base_url);
Ok(Redirect::to(base_url.to_string()))
}
None => Err(AppError::InvalidRequest(format!(
"No URL found for short code: {}",
url_short_code.0
))),
None => {
error!("No URL found for short code: {}", url_short_code.0);
Ok(Redirect::to(
app_state.expired_short_code_fallback_url.to_string(),
))
}
}
}
3 changes: 3 additions & 0 deletions crates/url_shortner/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct AppConfig {
pub max_retries_for_shortening: u8,
pub log_unprocessible_req_body: Vec<String>,
pub max_allowed_req_size: usize,
pub expired_short_code_fallback_url: String,
}

#[derive(Clone)]
Expand All @@ -41,6 +42,7 @@ pub struct AppState {
pub max_retries_for_shortening: u8,
pub log_unprocessible_req_body: Vec<String>,
pub max_allowed_req_size: usize,
pub expired_short_code_fallback_url: String,
}

impl AppState {
Expand All @@ -64,6 +66,7 @@ impl AppState {
max_retries_for_shortening: app_config.max_retries_for_shortening,
log_unprocessible_req_body: app_config.log_unprocessible_req_body,
max_allowed_req_size: app_config.max_allowed_req_size,
expired_short_code_fallback_url: app_config.expired_short_code_fallback_url,
}
}
}
1 change: 1 addition & 0 deletions dhall-configs/dev/url-shortner.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ in {
short_code_length = 6,
shortened_base_url = "http://localhost:9023",
max_retries_for_shortening = 5,
expired_short_code_fallback_url = "https://nammayatri.in",
}

0 comments on commit fe19d2c

Please sign in to comment.