diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/error.rs b/src/error.rs index 7daa103..a9b01bd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -128,13 +128,24 @@ impl ApiError { detail, operation_id, ), - crate::db::DbError::Query(error) => ApiError::new( - StatusCode::INTERNAL_SERVER_ERROR, - "database_error", - "Database error", - error.to_string(), - operation_id, - ), + crate::db::DbError::Query(error) => { + // A connection that died under the query is not the + // query's fault. Forget the pool so the next request + // cannot draw the same dead sockets -- this is the one + // place every database error passes through, so the + // recovery does not depend on each caller remembering it. + let api_error = ApiError::new( + StatusCode::INTERNAL_SERVER_ERROR, + "database_error", + "Database error", + error.to_string(), + operation_id, + ); + if crate::db::is_connection_loss(&crate::db::DbError::Query(error)) { + crate::db::forget_pool(); + } + api_error + } } } } |
