Sha256: 408023200d93bd562f9f809389993f0623b176826b1ca6ebd11fdcb2e11b3a15
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
class Agilibox::ErrorsMiddleware MAINTENANCE_ERRORS = [ "ActiveRecord::ConnectionTimeoutError", "connections on port 5432", "PG::UnableToSend", ] NOT_ACCEPTABLE_ERRORS = [ "ActionController::BadRequest", "ActionController::UnknownFormat", "ActionController::UnknownHttpMethod", "ActionDispatch::Cookies::CookieOverflow", "ActionDispatch::Http::MimeNegotiation::InvalidType", "ActionView::MissingTemplate", "Mime::Type::InvalidMimeType", ] def initialize(app) @app = app end def call(env) @app.call(env) 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) [status, {"Content-Type" => "text/plain; charset=UTF-8"}, [body]] end end stack = Rails.configuration.middleware mw = Agilibox::ErrorsMiddleware stack.unshift(mw) stack.insert_after(ActionDispatch::DebugExceptions, mw) if defined?(ActionDispatch::DebugExceptions) stack.insert_after(Bugsnag::Rack, mw) if defined?(Bugsnag::Rack) stack.use(mw)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
agilibox-2.0.0 | lib/agilibox/errors_middleware.rb |
agilibox-1.11.0 | lib/agilibox/errors_middleware.rb |