Skip to content

Commit

Permalink
Handle deadpool_postgres::PoolError
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Jul 14, 2024
1 parent 23b7c27 commit 2964cbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/errors/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ error_from! { transform tokio_postgres::Error, RouteError, |value| {
)
} }

error_from! { transform deadpool_postgres::PoolError, RouteError, |value| {
RouteError::ServerError(
ErrorCause::Database,
ErrorCode::External(value.to_string())
)
} }

impl ResponseError for RouteError {
fn status_code(&self) -> StatusCode {
match self {
Expand Down
4 changes: 2 additions & 2 deletions src/players.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn player_create(

let uuid = Uuid::new_v4();

let mut pg_client = pg_pool.get().await.unwrap();
let mut pg_client = pg_pool.get().await?;

let create_player_statement = pg_client
.prepare_typed_cached(
Expand Down Expand Up @@ -124,7 +124,7 @@ async fn player_authenticate(
)));
}

let pg_client = pg_pool.get().await.unwrap();
let pg_client = pg_pool.get().await?;

let find_token_statement = pg_client
.prepare_typed_cached(
Expand Down

0 comments on commit 2964cbc

Please sign in to comment.