Catching DBConnection.ConnectionErrors on DBConnection.Connection.connect/2

Hi there,

I’m having some intermittent network issues that result in a few DBConnection.ConnectionError raised by the Postgres adapter (I guess?!). These errors happen sporadically, but I would like to collect metrics whenever this type of errors happen.

[my_app] [error] 09:27:30.214 application=db_connection module=DBConnection.Connection function=connect/2  Postgrex.Protocol (#PID<0.536.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (postgres:5432): non-existing domain - :nxdomain

Currently I can only see them in the logs. I guess these errors are spit by the workers in the Ecto Repo? Is there a way to catch these errors? Maybe by indicating a callback to the Repo, that’s called whenever an error happens?

Thanks in advance!

I usually get errors like this when I lose internet connection. Or domain name is plain wrong.

3 Likes