super_exception_notifier 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/MIT-LICENSE +21 -0
  2. data/README.rdoc +528 -0
  3. data/VERSION.yml +4 -0
  4. data/init.rb +1 -0
  5. data/lib/exception_notifiable.rb +175 -0
  6. data/lib/exception_notifier.rb +185 -0
  7. data/lib/exception_notifier_helper.rb +60 -0
  8. data/lib/notifiable.rb +91 -0
  9. data/lib/super_exception_notifier/custom_exception_classes.rb +16 -0
  10. data/lib/super_exception_notifier/custom_exception_methods.rb +50 -0
  11. data/lib/super_exception_notifier/deprecated_methods.rb +60 -0
  12. data/lib/super_exception_notifier/git_blame.rb +52 -0
  13. data/lib/super_exception_notifier/helpful_hashes.rb +66 -0
  14. data/lib/super_exception_notifier/hooks_notifier.rb +55 -0
  15. data/lib/super_exception_notifier/notifiable_helper.rb +79 -0
  16. data/rails/app/views/exception_notifiable/400.html +5 -0
  17. data/rails/app/views/exception_notifiable/403.html +6 -0
  18. data/rails/app/views/exception_notifiable/404.html +6 -0
  19. data/rails/app/views/exception_notifiable/405.html +6 -0
  20. data/rails/app/views/exception_notifiable/410.html +7 -0
  21. data/rails/app/views/exception_notifiable/418.html +6 -0
  22. data/rails/app/views/exception_notifiable/422.html +5 -0
  23. data/rails/app/views/exception_notifiable/423.html +6 -0
  24. data/rails/app/views/exception_notifiable/501.html +8 -0
  25. data/rails/app/views/exception_notifiable/503.html +6 -0
  26. data/rails/app/views/exception_notifiable/method_disabled.html.erb +6 -0
  27. data/rails/init.rb +25 -0
  28. data/tasks/notified_task.rake +15 -0
  29. data/test/exception_notifiable_test.rb +34 -0
  30. data/test/exception_notifier_helper_test.rb +76 -0
  31. data/test/exception_notifier_test.rb +41 -0
  32. data/test/exception_notify_functional_test.rb +139 -0
  33. data/test/mocks/controllers.rb +82 -0
  34. data/test/notifiable_test.rb +79 -0
  35. data/test/test_helper.rb +32 -0
  36. data/views/exception_notifier/_backtrace.html.erb +1 -0
  37. data/views/exception_notifier/_environment.html.erb +14 -0
  38. data/views/exception_notifier/_inspect_model.html.erb +16 -0
  39. data/views/exception_notifier/_request.html.erb +8 -0
  40. data/views/exception_notifier/_session.html.erb +6 -0
  41. data/views/exception_notifier/_title.html.erb +3 -0
  42. data/views/exception_notifier/background_exception_notification.text.plain.erb +10 -0
  43. data/views/exception_notifier/exception_notification.text.plain.erb +15 -0
  44. metadata +119 -0
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2008 Peter Boling
2
+ # Copyright (c) 2005 Jamis Buck
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,528 @@
1
+ = Super Exception Notifier
2
+
3
+ The Super Exception Notifier (SEN) gem provides a mailer object and a default set of
4
+ templates for sending email notifications when errors occur in a Rails
5
+ application, as well as a default set of error page templates to render
6
+ based on the status code assigned to an error. The gem is configurable,
7
+ allowing programmers to customize (settings are per environment or per class):
8
+
9
+ * the sender address of the email
10
+ * the recipient addresses
11
+ * text used to prepend and append the subject line
12
+ * the HTTP status codes to send emails for
13
+ * the error classes to send emails for
14
+ * alternatively, the error classes to not send emails for
15
+ * whether to send error emails or just render without sending anything
16
+ * the HTTP status and status code that gets rendered with specific errors
17
+ * the view path to the error page templates
18
+ * custom errors, with custom error templates
19
+ * fine-grained customization of error layouts (or no layout)
20
+ * get error notification for errors that occur in the console, using notifiable method
21
+ * Hooks into `git blame` output so you can get an idea of who (may) have introduced the bug
22
+ * Hooks into other website services (e.g. you can send exceptions to to Switchub.com)
23
+ * Specify which level of notification you would like with an array of optional styles of notification:
24
+ [:render, :email, :web_hooks]
25
+
26
+ New features for 2.0.x:
27
+
28
+ * Can notify of errors occurring in any method in any class in Ruby by wrapping the method call like this:
29
+ notifiable { method }
30
+ * Can notify of errors in Rake tasks using 'NotifiedTask.new' instead of 'task' when writing tasks
31
+
32
+ The email includes information about the current request, session, and
33
+ environment, and also gives a backtrace of the exception.
34
+
35
+ This gem is based on the wonderful exception_notification plugin
36
+ created by Jamis Buck. I have modified it extensively and merged many of the improvements from
37
+ a dozen or so other forks. It remains a (mostly) drop in replacement with greatly extended
38
+ functionality and customization options. I keep it up to date with the work on the core team's
39
+ branch.
40
+
41
+ The original is here:
42
+
43
+ http://github.com/rails/exception_notification/tree/master
44
+
45
+ The current version of this gem is a git fork of the original and
46
+ has been updated to include the latest improvements from the original,
47
+ including compatability with Rails 2.1, 2.2, 2.3, and perhaps 3.0, as well as many improvements from
48
+ the other forks on github. I merge them in when I have time, and when the
49
+ changes fit nicely with the enhancements I have already made.
50
+
51
+ This fork of Exception Notifier is in production use on several large websites (top 5000).
52
+
53
+ == Installation
54
+
55
+ Gem Using Git building from source:
56
+
57
+ mkdir -p ~/src
58
+ cd ~/src
59
+ git clone git://github.com/pboling/exception_notification.git
60
+ cd exception_notification
61
+ gem build exception_notification.gemspec
62
+ sudo gem install super_exception_notification-2.0.0.gem # (Or whatever version gets built)
63
+
64
+ Then cd to your rails app to optionally freeze the gem into your app:
65
+
66
+ rake gems:freeze GEM=super_exception_notifier
67
+
68
+ Then in your environment.rb:
69
+
70
+ config.gem 'super_exception_notifier',
71
+ :version => '~> 2.0.0',
72
+ :lib => "exception_notifier"
73
+
74
+
75
+ Gemcutter is the hot new gem host, and you can use it like this:
76
+
77
+ [sudo] gem install gemcutter
78
+ [sudo] gem tumble # makes gemcutter gem source first in line
79
+ [sudo] gem install super_exception_notifier
80
+
81
+ Then in your environment.rb:
82
+
83
+ config.gem 'pboling-super_exception_notifier',
84
+ :version => '~> 2.0.0',
85
+ :lib => "exception_notifier",
86
+
87
+ Plugin using Git:
88
+
89
+ # Installation as plugin works too! (let me know if you find any bugs, as I don't ever run it this way.)
90
+ ./script/plugin install git://github.com/pboling/exception_notification.git
91
+
92
+ SVN Plugin (very deprecated, no longer updated, DO NOT USE, install Git!):
93
+
94
+ ./script/plugin install http://super-exception-notifier.googlecode.com/svn/trunk/super_exception_notifier
95
+
96
+ == Exceptions Without a Controller
97
+
98
+ You may also use SEN to send information about exceptions that
99
+ occur while running application scripts without a controller. Simply wrap the
100
+ code you want to watch with the notifiable method:
101
+
102
+ /PATH/TO/APP/script/runner -e production "notifiable { run_billing }"
103
+
104
+ Or from the console:
105
+
106
+ >> notifiable { Rails.this_method_does_not_exist }
107
+
108
+ == Exceptions in Rake Tasks
109
+
110
+ Use 'NotifiedTask.new' instead of 'task':
111
+
112
+ NotifiedTask.new :sometask => :environment do
113
+ puts "I'm a task"
114
+ end
115
+
116
+ == Exceptions Within a Controller
117
+
118
+ 1. Include the ExceptionNotifiable mixin in whichever controller you want
119
+ to generate error emails (typically ApplicationController):
120
+
121
+ class ApplicationController < ActionController::Base
122
+ include ExceptionNotifiable
123
+ ...
124
+ end
125
+
126
+ 2. Specify the email recipients in your environment:
127
+
128
+ ExceptionNotifier.configure_exception_notifier do |config|
129
+ config[:exception_recipients] = %w(joe@example.com bill@example.com)
130
+ end
131
+
132
+ 3. Make sure you have your ActionMailer server settings correct if you are using the e-mail features.
133
+
134
+ 4. That's it! The defaults take care of the rest.
135
+
136
+ == Basic Environment Configuration
137
+
138
+ These are settings that are global for SEN wherever it is used in your project.
139
+ You can tweak other values to your liking, as well. In your environment file,
140
+ just set any or all of the following values (defaults are shown):
141
+
142
+ ExceptionNotifier.configure_exception_notifier do |config|
143
+ # If left empty web hooks will not be engaged
144
+ config[:web_hooks] = []
145
+ config[:app_name] = "[MYAPP]"
146
+ # NOTE: THERE IS A BUG IN RAILS 2.3.3 which forces us to NOT use anything but a simple email address string for the sender address.
147
+ # https://rails.lighthouseapp.com/projects/8994/tickets/2340
148
+ config[:sender_address] = %("#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} Error" <super.exception.notifier@example.com>)
149
+ config[:exception_recipients] = []
150
+ # Customize the subject line
151
+ config[:subject_prepend] = "[#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} ERROR] "
152
+ config[:subject_append] = nil
153
+ # Include which sections of the exception email?
154
+ config[:sections] = %w(request session environment backtrace)
155
+ # Only use this gem to render, never email
156
+ #defaults to false - meaning by default it sends email. Setting true will cause it to only render the error pages, and NOT email.
157
+ config[:skip_local_notification] = true
158
+ # Example:
159
+ #config[:view_path] = 'app/views/error'
160
+ config[:view_path] = nil
161
+ # Error Notification will be sent if the HTTP response code for the error matches one of the following error codes
162
+ config[:notify_error_codes] = %W( 405 500 503 )
163
+ # Error Notification will be sent if the error class matches one of the following error error classes
164
+ config[:notify_error_classes] = %W( )
165
+ # What should we do for errors not listed?
166
+ config[:notify_other_errors] = true
167
+ # If you set this SEN will
168
+ config[:git_repo_path] = nil
169
+ config[:template_root] = "#{File.dirname(__FILE__)}/../views"
170
+ end
171
+
172
+ == Basic Controller Configuration
173
+
174
+ In any controller you do this:
175
+ include ExceptionNotifiable
176
+
177
+ Then that controller (or all of them if you put it in the application controller) will have its errors handled by SEN.
178
+ You can customize how each controller handles exceptions on a per controller basis, or all together in the application controller.
179
+ The available configuration options are shown with their default settings:
180
+
181
+ # HTTP status codes and what their 'English' status message is
182
+ self.http_status_codes = {
183
+ "400" => "Bad Request",
184
+ "403" => "Forbidden",
185
+ "404" => "Not Found",
186
+ "405" => "Method Not Allowed",
187
+ "410" => "Gone",
188
+ "418" => "I�m a teapot",
189
+ "422" => "Unprocessable Entity",
190
+ "423" => "Locked",
191
+ "500" => "Internal Server Error",
192
+ "501" => "Not Implemented",
193
+ "503" => "Service Unavailable"
194
+ }
195
+
196
+ # error_layout:
197
+ # can be defined at controller level to the name of the desired error layout,
198
+ # or set to true to render the controller's own default layout,
199
+ # or set to false to render errors with no layout
200
+ # syntax is the same as the rails 'layout' method (which is to say a string)
201
+ self.error_layout = nil
202
+
203
+ # Rails error classes to rescue and how to rescue them (which error code to use)
204
+ self.error_class_status_codes = {
205
+ # These are standard errors in rails / ruby
206
+ NameError => "503",
207
+ TypeError => "503",
208
+ RuntimeError => "500",
209
+ # These are custom error names defined in lib/super_exception_notifier/custom_exception_classes
210
+ AccessDenied => "403",
211
+ PageNotFound => "404",
212
+ InvalidMethod => "405",
213
+ ResourceGone => "410",
214
+ CorruptData => "422",
215
+ NoMethodError => "500",
216
+ NotImplemented => "501",
217
+ MethodDisabled => "200"
218
+ }
219
+
220
+ # Highly dependent on the verison of rails, so we're very protective about these'
221
+ self.error_class_status_codes.merge!({ ActionView::TemplateError => "500"}) if defined?(ActionView) && ActionView.const_defined?(:TemplateError)
222
+ self.error_class_status_codes.merge!({ ActiveRecord::RecordNotFound => "400" }) if defined?(ActiveRecord) && ActiveRecord.const_defined?(:RecordNotFound)
223
+ self.error_class_status_codes.merge!({ ActiveResource::ResourceNotFound => "404" }) if defined?(ActiveResource) && ActiveResource.const_defined?(:ResourceNotFound)
224
+
225
+ if defined?(ActionController)
226
+ self.error_class_status_codes.merge!({ ActionController::UnknownController => "404" }) if ActionController.const_defined?(:UnknownController)
227
+ self.error_class_status_codes.merge!({ ActionController::MissingTemplate => "404" }) if ActionController.const_defined?(:MissingTemplate)
228
+ self.error_class_status_codes.merge!({ ActionController::MethodNotAllowed => "405" }) if ActionController.const_defined?(:MethodNotAllowed)
229
+ self.error_class_status_codes.merge!({ ActionController::UnknownAction => "501" }) if ActionController.const_defined?(:UnknownAction)
230
+ self.error_class_status_codes.merge!({ ActionController::RoutingError => "404" }) if ActionController.const_defined?(:RoutingError)
231
+ self.error_class_status_codes.merge!({ ActionController::InvalidAuthenticityToken => "405" }) if ActionController.const_defined?(:InvalidAuthenticityToken)
232
+ end
233
+
234
+ # Verbosity of the gem (true or false) mainly useful for debugging
235
+ self.exception_notifiable_verbose = false
236
+
237
+ # Do Not Ever send error notification emails for these Error Classes
238
+ self.exception_notifiable_silent_exceptions = []
239
+ self.exception_notifiable_silent_exceptions << ActiveRecord::RecordNotFound if defined?(ActiveRecord)
240
+ if defined?(ActionController)
241
+ self.exception_notifiable_silent_exceptions << ActionController::UnknownController
242
+ self.exception_notifiable_silent_exceptions << ActionController::UnknownAction
243
+ self.exception_notifiable_silent_exceptions << ActionController::RoutingError
244
+ self.exception_notifiable_silent_exceptions << ActionController::MethodNotAllowed
245
+ end
246
+
247
+ # Notification Level
248
+ # Web Hooks, even though they are turned on by default, only get used if you actually configure them in the environment (see above)
249
+ # Email, even though it is turned on by default, only gets used if you actually configure recipients in the environment (see above)
250
+ self.exception_notifiable_notification_level = [:render, :email, :web_hooks]
251
+
252
+ == Environmental Behavior
253
+
254
+ Email notifications will only occur when the IP address is determined not to
255
+ be local. You can specify certain addresses to always be local so that you'll
256
+ get a detailed error instead of the generic error page. You do this in your
257
+ controller (or even per-controller):
258
+
259
+ consider_local "64.72.18.143", "14.17.21.25"
260
+
261
+ You can specify subnet masks as well, so that all matching addresses are
262
+ considered local:
263
+
264
+ consider_local "64.72.18.143/24"
265
+
266
+ The address "127.0.0.1" is always considered local. If you want to completely
267
+ reset the list of all addresses (for instance, if you wanted "127.0.0.1" to
268
+ NOT be considered local), you can simply do, somewhere in your controller:
269
+
270
+ local_addresses.clear
271
+
272
+ == Error Layout Customization
273
+
274
+ SEN allows you to specify the layout for errors at several levels:
275
+
276
+ * all errors use same layout site-wide
277
+ * customize a single controller
278
+ * can use the same layout as the controller
279
+ * no layout at all
280
+
281
+ By default it will render the error with the layout the controller is using. You just need to set in application.rb (assuming you included ExceptionNotifiable in applicaiton.rb) (or per-controller):
282
+
283
+ # All Same site-wide (in application.rb)
284
+ self.error_layout = 'my_error_layout'
285
+ # customize a single controller
286
+ self.error_layout = 'example_controller_error_layout'
287
+ # Same layout as the current controller is using
288
+ self.error_layout = true
289
+ # No layout at all
290
+ self.error_layout = false
291
+
292
+ SuperExceptionNotifier allows customization of the error classes that will be handled, and which HTTP status codes they will be handled as: (default values are shown)
293
+ Example in application.rb or on a per-controller basis:
294
+
295
+ self.http_status_codes = { "200" => "OK"
296
+ "400" => "Bad Request",
297
+ "403" => "Forbidden",
298
+ "404" => "Not Found",
299
+ "405" => "Method Not Allowed",
300
+ "410" => "Gone",
301
+ "500" => "Internal Server Error",
302
+ "501" => "Not Implemented",
303
+ "503" => "Service Unavailable" }
304
+
305
+ Q: Why is "200" listed as an error code?
306
+
307
+ A: You may want to have multiple custom errors that the standard HTTP status codes weren't designed to accommodate, and for which you need to render customized pages. Explanation and examples are a little further down...
308
+
309
+ Then you can specify which of those should send out emails!
310
+ By default, the email notifier will only notify on critical errors (405 500 503 statuses).
311
+ For example, ActiveRecord::RecordNotFound and ActionController::UnknownAction errors will simply render the contents of #{this gem's root}/rails/app/views/exception_notifiable/###.html file, where ### is 400 and 501 respectively.
312
+
313
+ ExceptionNotifier.config[:send_email_error_codes] = %w( 400 405 500 503 )
314
+
315
+ You can also configure the text of the HTTP request's response status code: (by default only the last 6 will be handled, the first 6 are made up error classes)
316
+ Example in application.rb or on a per-controller basis:
317
+
318
+ self.error_class_status_codes = {
319
+ NameError => "503",
320
+ TypeError => "503",
321
+ ActiveRecord::RecordNotFound => "400",
322
+ }
323
+
324
+ To make up your own error classes, you can define them in environment.rb, or in application.rb, or wherever you need them.
325
+ These are defined by the gem and are available to you in controllers once ExceptionNotifiable is included in application.rb or the current controller:
326
+
327
+ class AccessDenied < StandardError; end
328
+ class ResourceGone < StandardError; end
329
+ class NotImplemented < StandardError; end
330
+ class PageNotFound < StandardError; end
331
+ class InvalidMethod < StandardError; end
332
+ class CorruptData < StandardError; end
333
+ class MethodDisabled < StandardError; end
334
+
335
+ Methods like this are also defined by the gem in super_exception_notifier/custom_exception_methods.rb:
336
+ def access_denied
337
+ raise AccessDenied
338
+ end
339
+
340
+ They can be used like this in a controller:
341
+ before_filter :owner_required
342
+ protected
343
+ def owner_required
344
+ access_denied unless current_user.id == @photo.user_id
345
+ end
346
+ public
347
+ #... rest of controller
348
+
349
+ You may also configure which HTTP status codes will send out email: (by default = [], email sending is defined by status code only)
350
+
351
+ ExceptionNotifier.config[:send_email_error_classes] = [
352
+ NameError,
353
+ TypeError,
354
+ ActionController::RoutingError
355
+ ]
356
+
357
+ Email will be sent if the error matches one of the error classes to send email for OR if the error's assigned HTTP status code is configured to send email!
358
+
359
+ You can also customize what is rendered. SuperExceptionNotifier will render the first file it finds in this order:
360
+
361
+ #{RAILS_ROOT}/public/###.html
362
+ #{RAILS_ROOT}/#ExceptionNotifier.config[:view_path]}/###.html
363
+ #{this gem's root}/rails/app/views/exception_notifiable/#{status_cd}.html
364
+
365
+ And if none of those paths has a valid file to render, this one wins:
366
+
367
+ #{RAILS_ROOT}/rails/app/views/exception_notifiable/500.html
368
+
369
+ You can configure ExceptionNotifier.config[:view_path] in your environment file like this:
370
+
371
+ ExceptionNotifier.config[:view_path] = 'app/views/error'
372
+
373
+ So public trumps your custom path which trumps the gem's default path.
374
+
375
+ == Custom Error Pages
376
+
377
+ You can render CUSTOM error pages! Here's how:
378
+
379
+ 1. Make sure 200 is one of your status codes (optional)
380
+ * self.http_status_codes = { "200" => "OK" }
381
+ 2. Setup your custom error class, e.g. in config/environment.rb:
382
+ * class InsufficientFundsForWithdrawal < StandardError; end
383
+ 3. Setup SuperExceptionNotifier to handle the error, in app/controllers/application.rb:
384
+ * self.error_class_status_codes = { InsufficientFundsForWithdrawal => "200" }
385
+ 4. Set your custom error's view path:
386
+ * ExceptionNotifier.config[:view_path] = 'app/views/error'
387
+ 5. Create a view for the error. SuperExceptionNotifier munges the error's class by converting to a string and then replacing consecutive ':' with '' and then downcases it:
388
+ * touch app/views/error/insufficient_funds_for_withdrawal.html
389
+ 6. If you want a custom layout (by default it will render the error with the latout the controller is using) you just need to set, in application.rb (or per-controller):
390
+ * self.error_layout = 'my_error_layout' #or = true for the same layout as the controller, or = false for no layout
391
+ 7. That's it! All errors that are set to be handled with a status of "200" will render a custom page.
392
+ 8. If you want to have errors that render custom pages also send emails then you'll need to:
393
+ * ExceptionNotifier.config[:send_email_error_classes] = [ InsufficientFundsForWithdrawal ]
394
+
395
+ == Customization
396
+
397
+ By default, the notification email includes four parts: request, session,
398
+ environment, and backtrace (in that order). You can customize how each of those
399
+ sections are rendered by placing a partial named for that part in your
400
+ app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
401
+ access to the following variables:
402
+
403
+ * @controller: the controller that caused the error
404
+ * @request: the current request object
405
+ * @exception: the exception that was raised
406
+ * @host: the name of the host that made the request
407
+ * @backtrace: a sanitized version of the exception's backtrace
408
+ * @rails_root: a sanitized version of RAILS_ROOT
409
+ * @data: a hash of optional data values that were passed to the notifier
410
+ * @sections: the array of sections to include in the email
411
+
412
+ You can reorder the sections, or exclude sections completely, by altering the
413
+ ExceptionNotifier.config[:sections] variable.
414
+
415
+ == Not working due to nature of gem vs plugin
416
+
417
+ This might work if you install the gem as a plugin.
418
+
419
+ You can even add new sections that describe application-specific data --
420
+ just add the section's name to the list (wherever you'd like), and define the
421
+ corresponding partial. Then, if your new section requires information that isn't
422
+ available by default, make sure it is made available to the email using the
423
+ exception_data macro:
424
+
425
+ class ApplicationController < ActionController::Base
426
+ ...
427
+ protected
428
+ exception_data :additional_data
429
+
430
+ def additional_data
431
+ { :document => @document,
432
+ :person => @person }
433
+ end
434
+ ...
435
+ end
436
+
437
+ In the above case, @document and @person would be made available to the email
438
+ renderer, allowing your new section(s) to access and display them. See the
439
+ existing sections defined by the gem for examples of how to write your own.
440
+
441
+ == Advanced Customization
442
+
443
+ If you want to seriously modify the rules for the notification, you will need to implement your
444
+ own rescue_action_in_public method. You can look at the default implementation
445
+ in ExceptionNotifiable for an example of how to go about that.
446
+
447
+ == HTTP Error Codes Used by SEN by default
448
+
449
+ For reference these are the error codes that SEN can inherently handle.
450
+ Official w3.org HTTP 1.1 Error Codes:
451
+ http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
452
+ Not all the error codes in use today are on that list, so here's Apache's list:
453
+ http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#apache-response-codes-57
454
+
455
+ 400 Bad Request
456
+ * The request could not be understood by the server due to malformed syntax.
457
+ * The client SHOULD NOT repeat the request without modifications.
458
+ 403 Forbidden
459
+ * The server understood the request, but is refusing to fulfill it
460
+ 404 Not Found
461
+ * The server has not found anything matching the Request-URI
462
+ 405 Method Not Allowed
463
+ * The method specified in the Request-Line is not allowed for the resource identified by the Request-URI
464
+ * This is not implemented entirely as the response is supposed to contain a list of accepted methods.
465
+ 410 Gone
466
+ * The requested resource is no longer available at the server and no forwarding address is known. This condition is expected to be considered permanent
467
+ 418 I'm a teapot
468
+ * ErrorDocument I'm a teapot | Sample 418 I'm a teapot
469
+ * The HTCPCP server is a teapot. The responding entity MAY be short and stout. Defined by the April Fools specification RFC 2324. See Hyper Text Coffee Pot Control Protocol for more information.
470
+ 422 Unprocessable Entity
471
+ * ErrorDocument Unprocessable Entity | Sample 422 Unprocessable Entity
472
+ * (WebDAV) (RFC 4918 ) - The request was well-formed but was unable to be followed due to semantic errors.
473
+ 423 Locked
474
+ * ErrorDocument Locked | Sample 423 Locked
475
+ * (WebDAV) (RFC 4918 ) - The resource that is being accessed is locked
476
+ 500 Internal Server Error
477
+ * The server encountered an unexpected condition which prevented it from fulfilling the request.
478
+ 501 Not Implemented
479
+ * The server does not support the functionality required to fulfill the request.
480
+ 503 Service Unavailable
481
+ * The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.
482
+
483
+ == CSS
484
+
485
+ All the standard error pages that come in the gem render a div with a class of "dialog",
486
+ so put this in a stylesheet you are including in your app to get you started (like stardard rails error style):
487
+
488
+ <style type="text/css">
489
+ div.dialog {
490
+ width: 25em;
491
+ padding: 0 4em;
492
+ margin: 4em auto 0 auto;
493
+ border: 1px solid #ccc;
494
+ border-right-color: #999;
495
+ border-bottom-color: #999;
496
+ }
497
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
498
+ </style>
499
+
500
+
501
+ Copyright (c) 2008 Peter H. Boling, released under the MIT license
502
+ Portions Copyright (c) 2005 Jamis Buck, released under the MIT license
503
+
504
+ == jamescook changes
505
+
506
+ Hooks into `git blame` output so you can get an idea of who (may) have introduced the bug :)
507
+ -- Usage: set ExceptionNotifier.config[:git_repo_path] to the path of your git repo.
508
+
509
+
510
+ == ismasan changes
511
+
512
+ POST exception data in JSON format to the specified services for processing
513
+ -- Usage:
514
+ ExceptionNotifier.configure_exception_notifier do |config|
515
+ config[:web_hooks] = %w(http://some-hook-service.example.com http://another-hook-service.example.com) # defaults to []
516
+ config[:app_name] = "[APP]" # defaults to [MYAPP]
517
+ config[:exception_recipients] = %w(my@example.com another@example.com) # defaults to []
518
+ config[:sender_address] = %("Application Error" <app.error@myapp.com>) # defaults to super.exception.notifier@example.com
519
+ end
520
+
521
+ == sentientmonkey changes
522
+
523
+ Now you can get notifications from rake tasks!
524
+ Use 'NotifiedTask.new' instead of 'task':
525
+
526
+ NotifiedTask.new :sometask => :environment do
527
+ puts "I'm a task"
528
+ end