class Agilibox::ErrorsMiddleware

Constants

MAINTENANCE_ERRORS
NOT_ACCEPTABLE_ERRORS

Public Class Methods

new(app) click to toggle source
# File lib/agilibox/errors_middleware.rb, line 16
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/agilibox/errors_middleware.rb, line 20
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 Instance Methods

respond_with(status, body) click to toggle source
# File lib/agilibox/errors_middleware.rb, line 38
def respond_with(status, body)
  [status, {"Content-Type" => "text/plain; charset=UTF-8"}, [body]]
end