File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
Sources/PostgresConnectionPool Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -433,10 +433,31 @@ public actor PostgresConnectionPool {
433433 }
434434 catch {
435435 let connectionRuntime = fabs ( connectionStartTimestamp. timeIntervalSinceNow)
436- logger. debug ( " [ \( poolName) ] Connection \( poolConnection. id) failed after \( connectionRuntime. rounded ( toPlaces: 2 ) ) s: \( error) " )
437436 poolConnection. state = . closed
438437
439- // TODO: Don't just open a new connection, check first if this is a permanent error like wrong password etc.
438+ let logMessage : Logger . Message = " [ \( poolName) ] Connection \( poolConnection. id) failed after \( connectionRuntime. rounded ( toPlaces: 2 ) ) s: \( error) "
439+
440+ // Don't just open a new connection, check first if this is a permanent error like wrong password etc.
441+ if let pslError = error as? PSQLError ,
442+ let serverInfo = pslError. serverInfo,
443+ let code = serverInfo [ . sqlState]
444+ {
445+ // TODO: List of hard errors
446+ switch PostgresError . Code ( raw: code) {
447+ case . adminShutdown,
448+ . cannotConnectNow,
449+ . invalidAuthorizationSpecification,
450+ . invalidName,
451+ . invalidPassword:
452+ logger. error ( logMessage)
453+ return
454+
455+ default :
456+ break
457+ }
458+ }
459+
460+ logger. warning ( logMessage)
440461
441462 Task . detached { [ weak self] in
442463 await self ? . openConnection ( )
You can’t perform that action at this time.
0 commit comments