Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Created February 18, 2017 17:02
Show Gist options
  • Save mAlishera/56dd6779c884970c5889f39f370d3e38 to your computer and use it in GitHub Desktop.
Save mAlishera/56dd6779c884970c5889f39f370d3e38 to your computer and use it in GitHub Desktop.
MyMiddleware with PG::ConnectionBad rescue
class MyMiddleware
def initialize(app)
@app = app
end
def call(env)
dup._call(env)
end
def _call(env)
Rails.logger.send(:error, "External error ")
begin
@app.call(env)
rescue PG::ConnectionBad => e
Rails.logger.send(:error, "Internal error #{e} ")
perform_action(env)
end
end
private
def perform_action(env)
return ConfigsController.action(:new).call(env) unless action_create(env)
ConfigsController.action(:create).call(env)
end
def action_create(env)
env['REQUEST_METHOD'] == "POST" && env['PATH_INFO'] == "/admin/config"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment