From 84db442866ac77c8746fb4884634f757f140a6d0 Mon Sep 17 00:00:00 2001 From: Adrian Date: Tue, 15 Aug 2023 12:17:39 +0300 Subject: [PATCH] Return request extension for POST request (#17) * Return request extension for POST request * Make clippy happy --- src/routes/full_url.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/routes/full_url.rs b/src/routes/full_url.rs index 1ced939..10a088b 100644 --- a/src/routes/full_url.rs +++ b/src/routes/full_url.rs @@ -10,25 +10,30 @@ use uuid::Uuid; pub async fn full_url( State(data): State>, Json(payload): Json, -) { +) -> String { let mut retry_count = 3; while retry_count > 0 { let query_result = insert_in_db(&payload.url, State(data.clone())).await; match query_result { - Ok(note) => { - println!("okay received testing: {:?}", note); - break; + Ok(request) => { + println!("okay received testing: {:?}", request); + return request.extension; } Err(e) => { println!("failed with error: {:?}", e); //TODO : - For now assume is failing because of error code 23505, that stands for //duplicate key - retry_count += 1; + if retry_count == 1 { + return "error".to_string(); + } + retry_count -= 1; } } } + + "internal server error".to_string() } async fn insert_in_db(