Closed kuldeepaggarwal closed 10 months ago
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 ActiveRecord::RecordNotUnique
in rescuable_exceptions
. thanks!
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.