I am trying to create a health check page for my app. There are 3 different servers for back end, front end and database. I have created an API to check if services (sidekiq, redis) are running. Now, I want to check if postgres server is up or not. For this I have added a method
def database?
ActiveRecord::Base.connection.active?
end
This method returns true when postgres is running. If the Postgres server is stopped, and I try to hit my API I get
PG::ConnectionBad (could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
):
How to rescue this error?