From 6b9389cc239a92a8bf793d9c0ee310d410c96c40 Mon Sep 17 00:00:00 2001 From: nbari Date: Sat, 3 Feb 2024 09:37:48 +0100 Subject: [PATCH] 0.1.4 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- src/genesis/handlers/health.rs | 4 ++++ src/genesis/handlers/token.rs | 4 ++++ src/genesis/handlers/verify.rs | 3 +++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 311aa55..135b797 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1603,7 +1603,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "permesi-genesis" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "axum 0.7.4", @@ -2914,9 +2914,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ulid" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e3c3b4dcec1e4729aab50688a1a0631483d79e65b194851425e7748287715a6" +checksum = "34778c17965aa2a08913b57e1f34db9b4a63f5de31768b55bf20d2795f921259" dependencies = [ "getrandom", "rand", diff --git a/Cargo.toml b/Cargo.toml index d33c9d3..ddddf67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "permesi-genesis" -version = "0.1.3" +version = "0.1.4" edition = "2021" authors = ["Team Permesi "] description = "Token Zero generator for permesi" diff --git a/src/genesis/handlers/health.rs b/src/genesis/handlers/health.rs index 6310502..69b09ba 100644 --- a/src/genesis/handlers/health.rs +++ b/src/genesis/handlers/health.rs @@ -37,12 +37,14 @@ pub async fn health(method: Method, pool: Extension) -> impl IntoRespons Ok(()) => Ok(()), Err(error) => { error!("Failed to ping database: {}", error); + Err(StatusCode::SERVICE_UNAVAILABLE) } }, Err(error) => { error!("Failed to acquire database connection: {}", error); + Err(StatusCode::SERVICE_UNAVAILABLE) } }; @@ -93,11 +95,13 @@ pub async fn health(method: Method, pool: Extension) -> impl IntoRespons match result { Ok(()) => { debug!("Database connection is healthy"); + (StatusCode::OK, headers, body) } Err(status_code) => { debug!("Database connection is unhealthy"); + (status_code, headers, body) } } diff --git a/src/genesis/handlers/token.rs b/src/genesis/handlers/token.rs index 1aec4bc..ac22cbe 100644 --- a/src/genesis/handlers/token.rs +++ b/src/genesis/handlers/token.rs @@ -96,6 +96,7 @@ pub async fn token( Ok(tx) => tx, Err(err) => { error!("Failed to start transaction: {}", err); + return Err(( StatusCode::INTERNAL_SERVER_ERROR, "Failed to start transaction".to_string(), @@ -138,6 +139,7 @@ pub async fn token( Err(err) => { error!("Failed to commit transaction: {}", err); + Err((StatusCode::INTERNAL_SERVER_ERROR, err.to_string())) } }, @@ -145,10 +147,12 @@ pub async fn token( Err(err) => { match tx.rollback().await { Ok(()) => debug!("Rolled back transaction"), + Err(err) => error!("Failed to rollback transaction: {}", err), }; error!("Failed to insert token into database: {}", err); + Err((StatusCode::INTERNAL_SERVER_ERROR, err.to_string())) } } diff --git a/src/genesis/handlers/verify.rs b/src/genesis/handlers/verify.rs index 4b2c2f4..99c0ff5 100644 --- a/src/genesis/handlers/verify.rs +++ b/src/genesis/handlers/verify.rs @@ -38,15 +38,18 @@ pub async fn verify(Extension(pool): Extension, payload: Json) -> let valid: bool = row.get("valid"); if valid { debug!("Token is valid"); + StatusCode::ACCEPTED } else { error!("Token is invalid"); + StatusCode::FORBIDDEN } } Err(e) => { error!("Error while verifying token: {}", e); + StatusCode::INTERNAL_SERVER_ERROR } }