Request for Assistance: Overriding ResponseInterceptor Message for ConstraintViolationException

Hi,

Please, could you help me with how to override the ResponseInterceptor message to render an explicit message when a ConstraintViolationException error occurs?

I have tried to solve this using an Observer with several methods, but I haven’t been able to achieve the desired result.

Example:

The original message is:
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint « uk_20qqmat85osmhn8okihvyx3x0 »

  • Detail: Key (invoice_id, company)=(001, 1) already exists.*

The overridden and desired message is:
Error message,
The invoice for company N° 1 already exists, please check your …

You can catch this exception and throw new exception of the same type with another message, for example. This is in the case you are building your own module or modifying already existing module in Java, of course.