Exception Notification Plugin Question

Hi,

I have two questions re the Exception Notifier plugin (i.e. which you
install via “ruby script/plugin install exception_notification”)

Q1 - In it’s current setup (where it uses /public/500.html) is it
possible
to remove the “Status: 500 Internal Server Error Content-Type:
text/html”
text which seems to mysteriously get place at the top of the page?

Q2 - What’s the best way to add dynamic text to the error page? Should
I
change the following section of the plug-in to point to a normal Rails
action/rhtml view? But if I do this would this be making the design
brittle, i.e. what happens if there is a Rails internal issue itself
which
could mean it’s not possible for the error action/rhtml view to work?

def render_500
respond_to do |type|
type.html { render :file => “#{RAILS_ROOT}/public/500.html”,
:status
=> “500 Error” }
.
.

Tks
Greg

PS. In fact I think I may have been the scenario for which Exception
Notification was targeted at. Would the the below be correct:

[1] Uncaught Exception (i.e. not expected)
=> Exception Notification handles these / sends email

[2] Caught Exceptions (understood issue - can offer specific user
advice)
=> Use of custom application exception, global handler which can:
(a) send email alert, (b) display dynamic text in custom
application
error view.rhtml. That is concept is you can throw a custom app
exception anywhere in a model/controller and not have to worry
about
adding a handler/view.
=> QUESTION 1 - Where/how to catch such exception in the one spot and
and handle this? Extend Exception Notification plugin?

[3] Complex Business Rules (in Model, but not per field)
=> Use of Rails Validation framework but via adding validations
to :base within the error object

[4] Per Field Validations
=> Use of Rails Validations

I would also be interested to know how to do what Greg has mentioned.

With my web application, it would help me to pindown the issue if I know
the ID of the record in question. I’d like to add this to the exception
error.

Does anyone know the best way to do this?

Xin

Greg H. wrote:

Hi,

I have two questions re the Exception Notifier plugin (i.e. which you
install via “ruby script/plugin install exception_notification”)

Q1 - In it’s current setup (where it uses /public/500.html) is it
possible
to remove the “Status: 500 Internal Server Error Content-Type:
text/html”
text which seems to mysteriously get place at the top of the page?

Q2 - What’s the best way to add dynamic text to the error page? Should
I
change the following section of the plug-in to point to a normal Rails
action/rhtml view? But if I do this would this be making the design
brittle, i.e. what happens if there is a Rails internal issue itself
which
could mean it’s not possible for the error action/rhtml view to work?

def render_500
respond_to do |type|
type.html { render :file => “#{RAILS_ROOT}/public/500.html”,
:status
=> “500 Error” }
.
.

Tks
Greg

Xin,

I’ve ended up doing the following so far, some of which are adjustments
to
Jamis B.'some “Exception Notification” plugin. I’m still optimizing
this
for my own usage as I go. Hope this helps (any ideas/feedback welcome):

Usage:
if error_situation_occurs
raise Error.new( “Message to User Here - Will be shown on error page”,
“Additional message that will go to log file for
developers”,
Logger::ERROR)
end

Features:

  • Separate user & developer messages
  • Do not have to catch such errors back in controller or views as the
    below-mentioned rails rescue frame work will handle (i.e. less work,
    cleaner
    code)
  • Just need to raise the Error exception which then
    triggers/implies/carries
    out:
    (a) appropriate email message to user
    (b) developer specific additional message to logs
    © severity of log entry raised
    (b) triggers Email/SMS alert based on severity of the error (use of
    Ruby
    Logger severity levels)

class Error < RuntimeError
attr :developer_message
attr :severity

def initialize(user, dev=nil, sev=Logger::FATAL)
super user # Use normal exception parameter
for
User Message
@developer_message = dev || user # Set developer focused message
@severity = sev
end
end

def rescue_action_in_public(exception) # Override this Rails method
case exception
when *exceptions_to_treat_as_404
render_404
else
if exception.instance_of?(Error) # Added by Greg
# Custom Error (caught)
render_custom_error
case (exception.severity)
when Logger::FATAL
# trigger an email/sms for FATALs
send_notification(exception)
else
# no emails/sms otherwise - future step: have this
configurable in
environment.rb
end
else
# 500 Error (not caught)
render_500
send_notification(exception)
end
end
end

def render_custom_error
respond_to do |type|
type.html { render :template => “error/custom_500_error”}
type.all { render :nothing => true, :status => “500 Error” }
end
end

def log_error(exception) #:doc: # Override this Rails method
ActiveSupport::Deprecation.silence do
if ActionView::TemplateError === exception
logger.fatal(exception.to_s)
else
if exception.instance_of?(Error) # Added by Greg - logs the
User
Message, Log/Developer Message and limits stack trace to first 3 lines
# Custom Error (caught)
logger.error("#{exception.developer_message}\n" +
" Exception Class:#{exception.class}\n" +
" User Msg: #{exception.message}\n" +
" Backtrace:\n " + clean_backtrace(exception)[0…2].join("\n
“) + “\n\n”
)
else
logger.fatal(”#{exception.developer_message}\n" +
" Exception Class:#{exception.class}\n" +
" Backtrace:\n " + clean_backtrace(exception)[0…2].join("\n
") + “\n\n”
)
end
end
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs