Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mapping of Hibernate constraint violations #2204

Closed
Brutus5000 opened this issue Jul 22, 2021 · 0 comments · Fixed by #2205
Closed

Allow mapping of Hibernate constraint violations #2204

Brutus5000 opened this issue Jul 22, 2021 · 0 comments · Fixed by #2205

Comments

@Brutus5000
Copy link
Contributor

Hibernate generates very generic exceptions when you hit constraints i.e. unique column constraint. This result in very generic error response in Elide.

Desired Behavior

I want to be able to swap the nested ConstraintViolation with a proper business exception that returns proper error codes etc.

Current Behavior

Statuscode 423 Locked is returned with the generic text "could not execute statement".

Possible Solution

I can give Elide a Map<String, Function<ConstraintViolation, Throwable>> where the keys are the names of the constraint hit.
If a ConstraintViolation occurs, Elide will lookup the constraint name and if it finds one, will map the exception by calling the function from the map value.
I would implement this error mapping in the flush method of AbstractJpaTransaction. Not sure yet how to pass the map in there.

This would be a JpaDatastore only solution. Ideas for more general solutions are welcome.

Context

I'm trying to improve error handling for our frontend people.

Brutus5000 added a commit to Brutus5000/elide that referenced this issue Sep 13, 2021
aklish pushed a commit that referenced this issue Sep 13, 2021
* Add ability to map unknown exceptions to custom exceptions

Closes #2204

* Add tests for ErrorMapper

* Fix typo

* Add ErrorMapper to ElideStandalone

By default the mapper does not map anything.

* Add ErrorMapper to GraphQL QueryRunner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant