I'm trying to use optimistic locking in my application.
My code up until now (without optimistic locking) is reasonably clean.
Changesets, transactions, unique and foreign db constraints (through changesets), it all works well.
Now, when updating stale data (using optimistic_lock) an Ecto.StaleEntryError is thrown.
So far, I didn't have to catch errors, but I wonder how to properly handle Ecto.StaleEntryErrors being thrown in a GENERAL way.
By "in a GENERAL way" I mean I don't want to repeat this for every controller where it could happen.
How / where is this done best?
I could do some processing in the ErrorView module handling a server 500 error, but that doesn't seem to be the right (best) place.
And it feels late in the pipeline.
A try catch in the router is a possibility, but that doesn't feel right either.
(Basically my question applies also to Repo.get! or Repo.one! function calls failing with Ecto.NoResultsError)
Filip