123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::ActionableExceptions

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(app) ⇒ ActionableExceptions

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb', line 12

def initialize(app)
  @app = app
end

Class Attribute Details

.endpoint (rw) Also known as: #endpoint

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb', line 10

cattr_accessor :endpoint, default: "/rails/actions"

Instance Attribute Details

#endpoint (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb', line 10

cattr_accessor :endpoint, default: "/rails/actions"

Instance Method Details

#actionable_request?(request) ⇒ Boolean (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb', line 26

def actionable_request?(request)
  request.get_header("action_dispatch.show_detailed_exceptions") && request.post? && request.path == endpoint
end

#call(env)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb', line 16

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

#redirect_to(location) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb', line 30

def redirect_to(location)
  uri = URI.parse location

  if uri.relative? || uri.scheme == "http" || uri.scheme == "https"
    body = ""
  else
    return [400, { Rack::CONTENT_TYPE => "text/plain; charset=utf-8" }, ["Invalid redirection URI"]]
  end

  [302, {
    Rack::CONTENT_TYPE => "text/html; charset=#{Response.default_charset}",
    Rack::CONTENT_LENGTH => body.bytesize.to_s,
    ActionDispatch::Constants::LOCATION => location,
  }, [body]]
end