Class: Errplane::ExceptionPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/errplane/exception_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(e, params = {}) ⇒ ExceptionPresenter

Returns a new instance of ExceptionPresenter.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/errplane/exception_presenter.rb', line 18

def initialize(e, params = {})
  e = e.continued_exception if e.respond_to?(:continued_exception)
  e = e.original_exception if e.respond_to?(:original_exception)

  @exception = e.is_a?(String) ? Exception.new(e) : e
  @backtrace = Errplane::Backtrace.new(@exception.backtrace).to_a || []
  @params = params[:params]
  @session_data = params[:session_data] || {}
  @controller = params[:controller]
  @action = params[:action]
  @request_url = params[:request_url]
  @user_agent = params[:user_agent]
  @custom_data = params[:custom_data] || {}
  @environment_variables = ENV.to_hash || {}
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



13
14
15
# File 'lib/errplane/exception_presenter.rb', line 13

def action
  @action
end

#backtraceObject (readonly)

Returns the value of attribute backtrace.



9
10
11
# File 'lib/errplane/exception_presenter.rb', line 9

def backtrace
  @backtrace
end

#controllerObject (readonly)

Returns the value of attribute controller.



12
13
14
# File 'lib/errplane/exception_presenter.rb', line 12

def controller
  @controller
end

#custom_dataObject (readonly)

Returns the value of attribute custom_data.



16
17
18
# File 'lib/errplane/exception_presenter.rb', line 16

def custom_data
  @custom_data
end

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/errplane/exception_presenter.rb', line 8

def exception
  @exception
end

#hashObject

Returns the value of attribute hash.



6
7
8
# File 'lib/errplane/exception_presenter.rb', line 6

def hash
  @hash
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/errplane/exception_presenter.rb', line 10

def params
  @params
end

#request_urlObject (readonly)

Returns the value of attribute request_url.



14
15
16
# File 'lib/errplane/exception_presenter.rb', line 14

def request_url
  @request_url
end

#session_dataObject (readonly)

Returns the value of attribute session_data.



11
12
13
# File 'lib/errplane/exception_presenter.rb', line 11

def session_data
  @session_data
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



15
16
17
# File 'lib/errplane/exception_presenter.rb', line 15

def user_agent
  @user_agent
end

Instance Method Details

#contextObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/errplane/exception_presenter.rb', line 34

def context
  c = {
    :time => Time.now.utc.to_i,
    :application_name => Errplane.configuration.application_name,
    :application_root => Errplane.configuration.application_root,
    :framework => Errplane.configuration.framework,
    :framework_version => Errplane.configuration.framework_version,
    :message => @exception.message,
    :backtrace => @backtrace,
    :language => "Ruby",
    :language_version => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
    :reporter => reporter,
    :custom_data => @custom_data
  }

  c[:environment_variables] = @environment_variables.reject do |k,v|
    Errplane.configuration.environment_variable_filters.any? { |filter| k =~ filter }
  end

  Errplane.configuration.add_custom_exception_data(self)

  c[:request_data] = request_data if @controller || @action || !@params.blank?
  c
end

#dimensionsObject



59
60
61
62
63
64
65
66
67
# File 'lib/errplane/exception_presenter.rb', line 59

def dimensions
  d = {
    :Class => @exception.class.to_s,
    :class => @exception.class.to_s,
    :method => "#{@controller}##{@action}",
    :server => Socket.gethostname,
    :status => "open"
  }
end

#reporterObject



69
70
71
72
73
74
75
# File 'lib/errplane/exception_presenter.rb', line 69

def reporter
  {
    :name => "Errplane",
    :version => Errplane::VERSION,
    :url => "https://github.com/errplane/errplane-ruby"
  }
end

#request_dataObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/errplane/exception_presenter.rb', line 77

def request_data
  {
    :params => @params,
    :session_data => @session_data,
    :controller => @controller,
    :action => @action,
    :request_url => @request_url,
    :user_agent => @user_agent
  }
end