diff --git a/crates/url_shortner/src/domain/action/public_api.rs b/crates/url_shortner/src/domain/action/public_api.rs index c311ab3..f9c46aa 100644 --- a/crates/url_shortner/src/domain/action/public_api.rs +++ b/crates/url_shortner/src/domain/action/public_api.rs @@ -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(), + )) + } } } diff --git a/crates/url_shortner/src/environment.rs b/crates/url_shortner/src/environment.rs index cfe181e..86c9c61 100644 --- a/crates/url_shortner/src/environment.rs +++ b/crates/url_shortner/src/environment.rs @@ -25,6 +25,7 @@ pub struct AppConfig { pub max_retries_for_shortening: u8, pub log_unprocessible_req_body: Vec, pub max_allowed_req_size: usize, + pub expired_short_code_fallback_url: String, } #[derive(Clone)] @@ -41,6 +42,7 @@ pub struct AppState { pub max_retries_for_shortening: u8, pub log_unprocessible_req_body: Vec, pub max_allowed_req_size: usize, + pub expired_short_code_fallback_url: String, } impl AppState { @@ -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, } } } diff --git a/dhall-configs/dev/url-shortner.dhall b/dhall-configs/dev/url-shortner.dhall index ad25f56..901862e 100644 --- a/dhall-configs/dev/url-shortner.dhall +++ b/dhall-configs/dev/url-shortner.dhall @@ -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", } \ No newline at end of file