Sha256: f1fc566e76075bbfd897b9af17ff77a2a75e8a959bc333fb9ea3da9440ed4302

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

module Rexception
  class ExceptionsController < ActionController::Base
    STATUSES = Rack::Utils::SYMBOL_TO_STATUS_CODE.select { |_, code| code >= 400 }

    STATUSES.each do |status, code|
      eval <<-RUBY
        def #{status}
          render template_exists?(view) ? view : view(:application), status: #{code}
        end
      RUBY
    end

    layout -> { setting.layout }

    private

    def view(status = status())
      "#{setting.errors_dir}/#{status}"
    end

    def status
      self.class.status(env)
    end

    def setting
      Rexception.setting
    end

    class << self
      def call(env)
        action(status(env)).call(env)
      end

      def status(env)
        ActionDispatch::ExceptionWrapper.rescue_responses[exception(env).class.name]
      end

      def exception(env)
        env['action_dispatch.exception']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rexception-0.0.1 lib/rexception/controller.rb