From 2964cbc4905916fab3c2b2f77588b5f09800ebc5 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 14 Jul 2024 16:02:21 +0200 Subject: [PATCH] Handle deadpool_postgres::PoolError --- src/errors/api.rs | 7 +++++++ src/players.rs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/errors/api.rs b/src/errors/api.rs index 587cf8f..f0cba42 100644 --- a/src/errors/api.rs +++ b/src/errors/api.rs @@ -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 { diff --git a/src/players.rs b/src/players.rs index 2409b47..2105f04 100644 --- a/src/players.rs +++ b/src/players.rs @@ -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( @@ -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(