Associate `PostgresConnectionClosedException` with error code `08006`
rgmz opened this issue · comments
Feature Request
Is your feature request related to a problem? Please describe
When the connection is closed unexpectedly it throws a PostgresConnectionClosedException
. I would like to handle this scenario programmatically, however, it currently isn't possible to catch PostgresConnectionClosedException
because it's package-private.
For example, if I'm listening to notifications and want to restart the connection or channel.
Describe the solution you'd like
I would like for PostgresConnectionClosedException
to be public so it can be explicitly caught.
Describe alternatives you've considered
Presently the only alternative I'm aware of is catching R2dbcNonTransientResourceException
and checking for the "UNEXPECTED" error message. This isn't ideal because it's not as clear as catching the specific exception, and the message could change in the future.
Any R2dbcNonTransientResourceException
that does not implement the PostgresqlException
is an exceptional state that requires recovery. Driver exceptions that implement PostgresqlException
are error notifications sent by the database. PostgresConnectionClosedException
is a client-side exception and therefore it does not implement PostgresqlException
.
We do not want to expose internal exception types as the specification already defines a public API for exception signals.
We do not want to expose internal exception types as the specification already defines a public API for exception signals.
Would including specific error codes in R2dbcNonTransientResourceException
be a viable alternative? The MariaDB implementation includes relevant error codes (e.g. 0800
), and including Postgres error codes would be more meaningful than matching the exception reason.
Thanks for the suggestion. Reporting connection failure with the error code 08006
makes sense.