Responses from Spring -> Frontend

After reading the docs and trying out some thing I can’t figure out how to generate good error responses to the frontend.

Specific usecase: I have a service endpoint that might raise a DataIntegrityViolationException. If that happens I would love to have a status code(409) if this happens and a 400 for other error that can occur.
Can this be achieved somehow?

OOTB custom status codes are not support, but throwing EndpointException can be enhanced with custom subtype and/or message (still 400 status code) but can be handled easily in the front-end