[Rails] Re: Hook into Exception Chain
Hi Christoph,
Jeff
On Tuesday, November 12, 2013 6:40:12 AM UTC-8, sol wrote:
-- All you need to do is re-raise the exception after you're done using it in your rescue_from, so something along the lines of:
$ cat ./app/controllers/foo_controller.rb
...
rescue_from Exception do |e|
# do something with e before re-raising it ...
Rails.logger.debug("TEST: before re-raising ... e=#{e.inspect}")
raise e
end
...
def testfoo
x = 'bar' if 1/0
....
end
....
$ curl -sLi http://foo.localhost/testfoo
...
$ cat ./log/development.log
...
[c55f5] TEST: before re-raising ... e=#<ZeroDivisionError: divided by 0>
[c55f5] Completed 500 Internal Server Error in 17ms
[c55f5]
ZeroDivisionError (divided by 0):
app/controllers/foo_controller.rb:89:in `/'
app/controllers/foo_controller.rb:89:in `testfoo'
...
On Tuesday, November 12, 2013 6:40:12 AM UTC-8, sol wrote:
Hi there,I'm using Log4r in my rails projects. On log.error an email is sent using the EmailOutputter.I know changed the EmailOutputter to include a global var in the subject (MDC) since the subject is normally static.I want to set this var to the exception message, so it is sent as the subject.Can anyone tell me how to do this in rails?Basically:raise e or some other cause
-> Log4r::MDC.put('subject', e.message)
continue with the exceptionI found rescue_from but it just gives it to the handler and then stops.Thanks a lot,Christoph
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c3f25e2c-240d-4567-9058-a4c0b6c1232d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home