Created
February 18, 2017 17:02
-
-
Save mAlishera/56dd6779c884970c5889f39f370d3e38 to your computer and use it in GitHub Desktop.
MyMiddleware with PG::ConnectionBad rescue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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