lib/agilibox/errors_middleware.rb in agilibox-1.9.1 vs lib/agilibox/errors_middleware.rb in agilibox-1.9.3

- old
+ new

@@ -1,26 +1,36 @@ class Agilibox::ErrorsMiddleware MAINTENANCE_ERRORS = [ - PG::ConnectionBad, - PG::UnableToSend, + "ActiveRecord::ConnectionTimeoutError", + "connections on port 5432", + "PG::UnableToSend", ] NOT_ACCEPTABLE_ERRORS = [ - ActionController::UnknownFormat, - ActionController::UnknownHttpMethod, - ActionView::MissingTemplate, + "ActionController::BadRequest", + "ActionController::UnknownFormat", + "ActionController::UnknownHttpMethod", + "ActionView::MissingTemplate", ] def initialize(app) @app = app end def call(env) @app.call(env) - rescue *MAINTENANCE_ERRORS - respond_with 503, "Maintenance en cours." - rescue *NOT_ACCEPTABLE_ERRORS - respond_with 406, "Not acceptable." + rescue StandardError => e + error = "#{e.class} : #{e.message}" + + if MAINTENANCE_ERRORS.any? { |pattern| error.match?(pattern) } + return respond_with 503, "Maintenance en cours." + end + + if NOT_ACCEPTABLE_ERRORS.any? { |pattern| error.match?(pattern) } + return respond_with 406, "Not acceptable." + end + + raise e end private def respond_with(status, body)