FIX: Improved error message in the case of SQL constraint violation on foreign keys #4167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brief description of the PR.
I wanted to return a more specific error message that notifies clients that they are trying to break a fk constraints, to let them know precisely what they are doing wrong. Currently, in such cases, a too general 500 internal persistence error is returned
Description of the solution adopted
With these changes, a 409 error is returned instead, with a message that notifies precisely a fk violation if it's detected. Otherwise, a more general error message is returned if other SQL constraint violations are present