Allow access to io.r2dbc.postgresql.ExceptionFactory
exceptions from client code
#644
Labels
status: waiting-for-feedback
We need additional information before we can continue
type: enhancement
A general enhancement
Feature Request
Is your feature request related to a problem? Please describe
When using this driver via Spring, when exceptions that this driver throws occur, Spring wraps them into wrapper exceptions such that different drivers can be used (e.g., JPA, Hibernate, R2DBC, etc.).
My example is the
org.springframework.dao.DataIntegrityViolationException
(the name implies when it occurs), which wraps around aThrowable cause
that the driver threw. When using this R2DBC driver, that cause isio.r2dbc.postgresql.ExceptionFactory.PostgresqlDataIntegrityViolationException
.My use case was to access which constraint was violated in an
UPDATE
query to rethrow the exception with a specific human-readable error message (instead ofviolates unique constraint \"%s\"
).Sadly, since all the exceptions produced by the
ExceptionFactory
are non-public, I cannot import them into my client code to perform a cast of theThrowable cause
of Spring's exception to then access theErrorDetails
of the driver's exception which would contain the constraint that was violated which I am after, such as:Unfortunately, this code does not compile.
Describe the solution you'd like
If the exceptions produced by
io.r2dbc.postgresql.ExceptionFactory
werepublic
, the above example code would work.For instance, Hibernate or JPA do support this "correctly" via e.g.,
HibernateExceptionTranslator
that will (to stay with my example) bubble up aorg.hibernate.exception.ConstraintViolationException
as theThrowable cause
of Spring's wrapper exception which ispublic
, thus making this code compile (in current Java versions):Describe alternatives you've considered
N/A
Teachability, Documentation, Adoption, Migration Strategy
N/A
The text was updated successfully, but these errors were encountered: