Skip to content

Advanced Controller Configuration

triemstr edited this page Sep 13, 2010 · 2 revisions

In any controller you do this:

include ExceptionNotification::ExceptionNotifiable

Then that controller (or all of them if you put it in the application controller) will have its errors handled by SEN.
You can customize how each controller handles exceptions on a per controller basis, or all together in the application controller.
The available configuration options are shown with their default settings, pulled from the gem’s source:

#  HTTP status codes and what their 'English' status message is
self.http_status_codes = {
  "400" => "Bad Request",
  "403" => "Forbidden",
  "404" => "Not Found",
  "405" => "Method Not Allowed",
  "410" => "Gone",
  "418" => "I'm a teapot",
  "422" => "Unprocessable Entity",
  "423" => "Locked",
  "500" => "Internal Server Error",
  "501" => "Not Implemented",
  "503" => "Service Unavailable"
}
# error_layout:
#   can be defined at controller level to the name of the desired error layout,
#   or set to true to render the controller's own default layout,
#   or set to false to render errors with no layout
#   syntax is the same as the rails 'layout' method (which is to say a string)
self.error_layout = nil
# Rails error classes to rescue and how to rescue them (which error code to use)
self.error_class_status_codes = {
  # These are standard errors in rails / ruby
  NameError => "503",
  TypeError => "503",
  RuntimeError => "500",
  # These are custom error names defined in lib/super_exception_notifier/custom_exception_classes
  AccessDenied => "403",
  PageNotFound => "404",
  InvalidMethod => "405",
  ResourceGone => "410",
  CorruptData => "422",
  NoMethodError => "500",
  NotImplemented => "501",
  MethodDisabled => "200"
}
# Highly dependent on the version of rails, so we're very protective about these'
self.error_class_status_codes.merge!({ ActionView::TemplateError => "500"})             if defined?(ActionView)       && ActionView.const_defined?(:TemplateError)
self.error_class_status_codes.merge!({ ActiveRecord::RecordNotFound => "400" })         if defined?(ActiveRecord)     && ActiveRecord.const_defined?(:RecordNotFound)
self.error_class_status_codes.merge!({ ActiveResource::ResourceNotFound => "404" })     if defined?(ActiveResource)   && ActiveResource.const_defined?(:ResourceNotFound)
if defined?(ActionController)
  self.error_class_status_codes.merge!({ ActionController::UnknownController => "404" })          if ActionController.const_defined?(:UnknownController)
  self.error_class_status_codes.merge!({ ActionController::MissingTemplate => "404" })            if ActionController.const_defined?(:MissingTemplate)
  self.error_class_status_codes.merge!({ ActionController::MethodNotAllowed => "405" })           if ActionController.const_defined?(:MethodNotAllowed)
  self.error_class_status_codes.merge!({ ActionController::UnknownAction => "501" })              if ActionController.const_defined?(:UnknownAction)
  self.error_class_status_codes.merge!({ ActionController::RoutingError => "404" })               if ActionController.const_defined?(:RoutingError)
  self.error_class_status_codes.merge!({ ActionController::InvalidAuthenticityToken => "405" })   if ActionController.const_defined?(:InvalidAuthenticityToken)
end
# Verbosity of the gem (true or false) mainly useful for debugging
self.exception_notifiable_verbose = false
# Do Not Ever send error notification emails for these Error Classes
self.exception_notifiable_silent_exceptions = []
self.exception_notifiable_silent_exceptions << ActiveRecord::RecordNotFound if defined?(ActiveRecord)
if defined?(ActionController)
  self.exception_notifiable_silent_exceptions << ActionController::UnknownController
  self.exception_notifiable_silent_exceptions << ActionController::UnknownAction
  self.exception_notifiable_silent_exceptions << ActionController::RoutingError
  self.exception_notifiable_silent_exceptions << ActionController::MethodNotAllowed
end
# Notification Level
# Web Hooks, even though they are turned on by default, only get used if you actually configure them in the environment (see above)
# Email, even though it is turned on by default, only gets used if you actually configure recipients in the environment (see above)
self.exception_notifiable_notification_level = [:render, :email, :web_hooks]
# Environments
# Only turned on in production (default below).  Add other environments if needed: ["staging", "production"]
self.exception_notifiable_noisy_environments = ["production"]