Sha256: 7ab03fe955481370f5c0d01fb7ba7c8d0c760c3e5fb4398512d83ef7d41673b8

Contents?: true

Size: 1.09 KB

Versions: 25

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require "erb"
require "action_dispatch/http/request"
require "active_support/actionable_error"

module ActionDispatch
  class ActionableExceptions # :nodoc:
    cattr_accessor :endpoint, default: "/rails/actions"

    def initialize(app)
      @app = app
    end

    def call(env)
      request = ActionDispatch::Request.new(env)
      return @app.call(env) unless actionable_request?(request)

      ActiveSupport::ActionableError.dispatch(request.params[:error].to_s.safe_constantize, request.params[:action])

      redirect_to request.params[:location]
    end

    private
      def actionable_request?(request)
        request.show_exceptions? && request.post? && request.path == endpoint
      end

      def redirect_to(location)
        body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"

        [302, {
          "Content-Type" => "text/html; charset=#{Response.default_charset}",
          "Content-Length" => body.bytesize.to_s,
          "Location" => location,
        }, [body]]
      end
  end
end

Version data entries

25 entries across 23 versions & 5 rubygems

Version Path
actionpack-6.0.3.1 lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.3 lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.3.rc1 lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.2.2 lib/action_dispatch/middleware/actionable_exceptions.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/actionable_exceptions.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.2.1 lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.2 lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.2.rc2 lib/action_dispatch/middleware/actionable_exceptions.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-6.0.1/lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.2.rc1 lib/action_dispatch/middleware/actionable_exceptions.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-6.0.1/lib/action_dispatch/middleware/actionable_exceptions.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.1 lib/action_dispatch/middleware/actionable_exceptions.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb
actionpack-6.0.1.rc1 lib/action_dispatch/middleware/actionable_exceptions.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/middleware/actionable_exceptions.rb