-
Notifications
You must be signed in to change notification settings - Fork 44
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
Handle from activerecord error(s) while saving the record #58
Comments
No objections in principle! Are you thinking of creating a PR or wanting us to do this from our side based on the suggestion in this GitHub issue? |
I can raise the PR if we are okay with the approach. |
@kuldeepaggarwal (Belatedly, sorry) Yes, something like that would work. Please note some minor changes to the code in that area in the current branch, with the bulk of the actual exception handling moved into a new method but otherwise, the idea of rescuing a configurable list of exceptions would be applied in the same way as you suggest. |
Since I've allocated myself a couple of days to work on Scimitar backlog stuff, I'm implementing this now, so no need for a new PR at this point. |
@pond please also include |
Implement suggestion from #58, with test coverage
This is now in v2.7.0. |
...and v1.8.0. |
SCIMitar gem relies on the fact that Rails throw
ActiveRecord::RecordInvalid
only if the record is invalid however, Rails can also raiseRecordNotSaved
error in case of the object is not stored.In case of
RecordNotSaved
, we should returnResourceInvalidError
error(status_code=400) from SCIMitar instead of 500 status code.activerecord-rescue_from_duplicate is a gem that we can use to rescue from DB level unique errors in case of race condition.
Adding DB level unique constraint guarantees uniqueness else we could have duplicate records.
And
activerecord-rescue_from_duplicate
raisesRecordNotSaved
error in case we receive unique validation error from MYSQL.Note: SCIM server should respond with 409 in this case.
Proposal
So, I am proposing a slight change in the implementation:
This way, this will be extendible in the future for the consumer(like us) to add more custom exceptions in the list if we want to return
Scimitar::ResourceInvalidError
for particular exceptions.The text was updated successfully, but these errors were encountered: