Sha256: 0b542d91b1590ca5e3050cd53e12a2cd2de07296c9c682a224d342d68952b1e8

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 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 -> { layout }

    private

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

    def status
      self.class.status(env)
    end

    def layout
      Rexception.layout
    end

    def errors_dir
      Rexception.errors_dir
    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.1.0 lib/rexception/exceptions_controller.rb