elixir-ecto / db_connection

Database connection behaviour

Home Page:http://hexdocs.pm/db_connection/DBConnection.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Turn `ConnectionError` into an error tuple (vs exception)

acco opened this issue · comments

Hey team,

DbConnection.ConnectionErrors happen. We obviously have worked to minimize, but there are some high-volume tables in our app that will run into this issue from time to time.

The problem is that unlike other errors, a ConnectionError is an exception. This complicates our control flow: instead of being able to use a with clause to handle all the possible things that can go wrong, we have to do some extra try/rescue wrapping to handle these exceptions.

Is there any appetite for making this behavior configurable? Or am I missing something here? It would be great to have a start_link/1 setting that flipped connection errors to a tuple instead of an exception. With some guidance, I'd be happy to help make it happen.

I would love to see a PR exploring this and we can decide based on that if it is not too much work.

Ok @josevalim ! I'll see what I can whip up

@josevalim Would love any feedback you have on a PR I put together. Thank you in advance.

Per #264 (comment), think it makes the most sense to just funnel all calls to Postgrex.query into one location in our app and rescue the exception. Thanks all!