123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::ExceptionWrapper

Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/middleware/exception_wrapper.rb

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(env, exception) ⇒ ExceptionWrapper

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 33

def initialize(env, exception)
  @env = env
  @exception = original_exception(exception)

  expand_backtrace if exception.is_a?(SyntaxError) || exception.try(:original_exception).try(:is_a?, SyntaxError)
end

Class Attribute Details

.rescue_responses (rw) Also known as: #rescue_responses

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 6

cattr_accessor :rescue_responses

.rescue_templates (rw) Also known as: #rescue_templates

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 22

cattr_accessor :rescue_templates

Class Method Details

.status_code_for_exception(class_name)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 84

def self.status_code_for_exception(class_name)
  Rack::Utils.status_code(@@rescue_responses[class_name])
end

Instance Attribute Details

#env (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 31

attr_reader :env, :exception, :line_number, :file

#exception (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 31

attr_reader :env, :exception, :line_number, :file

#file (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 31

attr_reader :env, :exception, :line_number, :file

#line_number (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 31

attr_reader :env, :exception, :line_number, :file

#rescue_responses (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 6

cattr_accessor :rescue_responses

#rescue_templates (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 22

cattr_accessor :rescue_templates

Instance Method Details

#application_trace

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 48

def application_trace
  clean_backtrace(:silent)
end

#framework_trace

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 52

def framework_trace
  clean_backtrace(:noise)
end

#full_trace

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 56

def full_trace
  clean_backtrace(:all)
end

#rescue_template

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 40

def rescue_template
  @@rescue_templates[@exception.class.name]
end

#source_extracts

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 88

def source_extracts
  backtrace.map do |trace|
    file, line = trace.split(":")
    line_number = line.to_i

    {
      code: source_fragment(file, line_number),
      line_number: line_number
    }
  end
end

#status_code

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 44

def status_code
  self.class.status_code_for_exception(@exception.class.name)
end

#traces

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/exception_wrapper.rb', line 60

def traces
  appplication_trace_with_ids = []
  framework_trace_with_ids = []
  full_trace_with_ids = []

  full_trace.each_with_index do |trace, idx|
    trace_with_id = { id: idx, trace: trace }

    if application_trace.include?(trace)
      appplication_trace_with_ids << trace_with_id
    else
      framework_trace_with_ids << trace_with_id
    end

    full_trace_with_ids << trace_with_id
  end

  {
    "Application Trace" => appplication_trace_with_ids,
    "Framework Trace" => framework_trace_with_ids,
    "Full Trace" => full_trace_with_ids
  }
end