I am implementing a REST API with Jersey and jOOQ.
I have a table with some constraints, for example a unique key. When inserting a tuple which violates this constraint, jOOQ throws a DataAccessException
:
org.jooq.exception.DataAccessException: SQL [insert into ...]; ERROR: duplicate key value violates unique constraint "issue_name_key"
Is there a way to find out which constraint has been violated, without string-parsing the error message? If a constraint is violated, I want to return a 400 bad request
http status code instead of a 500 general error
.
If this is not possible, what is common practise here? Should I query the database for each possible constraint violation? This smells like a maintenance trap.
e.getCause()
on the JOOQ exception to drill down. – YurikPSQLException
without further distinction. – Mauser