Class: ExceptionEngine::Notice

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_engine/notice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Notice

Returns a new instance of Notice.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/exception_engine/notice.rb', line 69

def initialize(args)
  self.args         = args
  self.exception    = args[:exception]
  self.api_key      = args[:api_key]
  self.project_root = args[:project_root]
  self.url          = args[:url] || rack_env(:url)

  self.notifier_name    = args[:notifier_name]
  self.notifier_version = args[:notifier_version]
  self.notifier_url     = args[:notifier_url]

  self.ignore              = args[:ignore]              || []
  self.ignore_by_filters   = args[:ignore_by_filters]   || []
  self.backtrace_filters   = args[:backtrace_filters]   || []
  self.params_filters      = args[:params_filters]      || []
  self.parameters          = args[:parameters] ||
                               action_dispatch_params ||
                               rack_env(:params) ||
                               {}
  self.component           = args[:component] || args[:controller] || parameters['controller']
  self.action              = args[:action] || parameters['action']

  self.environment_name = args[:environment_name]
  self.cgi_data         = args[:cgi_data] || args[:rack_env]
  self.backtrace        = Backtrace.parse(exception_attribute(:backtrace, caller), :filters => self.backtrace_filters)
  self.error_class      = exception_attribute(:error_class) {|exception| exception.class.name }
  self.error_message    = exception_attribute(:error_message, 'Notification') do |exception|
    "#{exception.class.name}: #{exception.message}"
  end

  also_use_rack_params_filters
  find_session_data
  clean_params
  clean_rack_request_data
end

Instance Attribute Details

#actionObject

The action (if any) that was called in this request



43
44
45
# File 'lib/exception_engine/notice.rb', line 43

def action
  @action
end

#api_keyObject

The API key for the project to which this notice should be sent



11
12
13
# File 'lib/exception_engine/notice.rb', line 11

def api_key
  @api_key
end

#backtraceObject

The backtrace from the given exception or hash.



14
15
16
# File 'lib/exception_engine/notice.rb', line 14

def backtrace
  @backtrace
end

#backtrace_filtersObject

See Configuration#backtrace_filters



29
30
31
# File 'lib/exception_engine/notice.rb', line 29

def backtrace_filters
  @backtrace_filters
end

#cgi_dataObject

CGI variables such as HTTP_METHOD



23
24
25
# File 'lib/exception_engine/notice.rb', line 23

def cgi_data
  @cgi_data
end

#componentObject Also known as: controller

The component (if any) which was used in this request (usually the controller)



39
40
41
# File 'lib/exception_engine/notice.rb', line 39

def component
  @component
end

#environment_nameObject

The name of the server environment (such as “production”)



20
21
22
# File 'lib/exception_engine/notice.rb', line 20

def environment_name
  @environment_name
end

#error_classObject

The name of the class of error (such as RuntimeError)



17
18
19
# File 'lib/exception_engine/notice.rb', line 17

def error_class
  @error_class
end

#error_messageObject

The message from the exception, or a general description of the error



26
27
28
# File 'lib/exception_engine/notice.rb', line 26

def error_message
  @error_message
end

#exceptionObject

The exception that caused this notice, if any



8
9
10
# File 'lib/exception_engine/notice.rb', line 8

def exception
  @exception
end

#ignoreObject

See Configuration#ignore



55
56
57
# File 'lib/exception_engine/notice.rb', line 55

def ignore
  @ignore
end

#ignore_by_filtersObject

See Configuration#ignore_by_filters



58
59
60
# File 'lib/exception_engine/notice.rb', line 58

def ignore_by_filters
  @ignore_by_filters
end

#notifier_nameObject

The name of the notifier library sending this notice, such as “Hoptoad Notifier”



61
62
63
# File 'lib/exception_engine/notice.rb', line 61

def notifier_name
  @notifier_name
end

#notifier_urlObject

A URL for more information about the notifier library sending this notice



67
68
69
# File 'lib/exception_engine/notice.rb', line 67

def notifier_url
  @notifier_url
end

#notifier_versionObject

The version number of the notifier library sending this notice, such as “2.1.3”



64
65
66
# File 'lib/exception_engine/notice.rb', line 64

def notifier_version
  @notifier_version
end

#parametersObject Also known as: params

A hash of parameters from the query string or post body.



35
36
37
# File 'lib/exception_engine/notice.rb', line 35

def parameters
  @parameters
end

#params_filtersObject

See Configuration#params_filters



32
33
34
# File 'lib/exception_engine/notice.rb', line 32

def params_filters
  @params_filters
end

#project_rootObject

The path to the project that caused the error (usually RAILS_ROOT)



49
50
51
# File 'lib/exception_engine/notice.rb', line 49

def project_root
  @project_root
end

#session_dataObject

A hash of session data from the request



46
47
48
# File 'lib/exception_engine/notice.rb', line 46

def session_data
  @session_data
end

#urlObject

The URL at which the error occurred (if any)



52
53
54
# File 'lib/exception_engine/notice.rb', line 52

def url
  @url
end

Instance Method Details

#[](method) ⇒ Object

Allows properties to be accessed using a hash-like syntax

Examples:

notice[:error_message]

Parameters:

  • method (String)

    The given key for an attribute

Returns:

  • The attribute value, or self if given :request



174
175
176
177
178
179
180
181
# File 'lib/exception_engine/notice.rb', line 174

def [](method)
  case method
  when :request
    self
  else
    send(method)
  end
end

#ignore?Boolean

Determines if this notice should be ignored

Returns:

  • (Boolean)


163
164
165
166
# File 'lib/exception_engine/notice.rb', line 163

def ignore?
  ignored_class_names.include?(error_class) ||
    ignore_by_filters.any? {|filter| filter.call(self) }
end

#to_xmlObject

Converts the given notice to XML



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/exception_engine/notice.rb', line 106

def to_xml
  builder = Builder::XmlMarkup.new
  builder.instruct!
  xml = builder.notice(:version => "1.0") do |notice|
    notice.tag!("api-key", api_key)
    notice.notifier do |notifier|
      notifier.name(notifier_name)
      notifier.version(notifier_version)
      notifier.url(notifier_url)
    end
    notice.error do |error|
      error.tag!('class', error_class)
      error.message(error_message)
      error.backtrace do |backtrace|
        self.backtrace.lines.each do |line|
          backtrace.line(:number => line.number,
                         :file   => line.file,
                         :method => line.method)
        end
      end
    end
    if url ||
        controller ||
        action ||
        !parameters.blank? ||
        !cgi_data.blank? ||
        !session_data.blank?
      notice.request do |request|
        request.url(url)
        request.component(controller)
        request.action(action)
        unless parameters.nil? || parameters.empty?
          request.params do |params|
            xml_vars_for(params, parameters)
          end
        end
        unless session_data.nil? || session_data.empty?
          request.session do |session|
            xml_vars_for(session, session_data)
          end
        end
        unless cgi_data.nil? || cgi_data.empty?
          request.tag!("cgi-data") do |cgi_datum|
            xml_vars_for(cgi_datum, cgi_data)
          end
        end
      end
    end
    notice.tag!("server-environment") do |env|
      env.tag!("project-root", project_root)
      env.tag!("environment-name", environment_name)
    end
  end
  xml.to_s
end