Skip to content

Commit

Permalink
0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Feb 3, 2024
1 parent 02bd82d commit 6b9389c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "permesi-genesis"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
authors = ["Team Permesi <team@permesi.dev>"]
description = "Token Zero generator for permesi"
Expand Down
4 changes: 4 additions & 0 deletions src/genesis/handlers/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ pub async fn health(method: Method, pool: Extension<PgPool>) -> 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)
}
};
Expand Down Expand Up @@ -93,11 +95,13 @@ pub async fn health(method: Method, pool: Extension<PgPool>) -> 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)
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/genesis/handlers/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -138,17 +139,20 @@ pub async fn token(

Err(err) => {
error!("Failed to commit transaction: {}", err);

Err((StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))
}
},

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()))
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/genesis/handlers/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ pub async fn verify(Extension(pool): Extension<PgPool>, payload: Json<Token>) ->
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
}
}
Expand Down

0 comments on commit 6b9389c

Please sign in to comment.