[Rails] Re: Hook into Exception Chain
Thanks a lot! That's useful
On Saturday, 16 November 2013 22:36:35 UTC+1, Frederick Cheung wrote:
-- On Saturday, 16 November 2013 22:36:35 UTC+1, Frederick Cheung wrote:
On Friday, November 15, 2013 10:26:10 AM UTC, sol wrote:I've used the above approach nowHowever, this only works for controller actions.I've got some cronjobs in the project (lib folder) as well as a sinatra app that is mounted within the rails app.Is there any way I could catch the exceptions in these parts as well?For a cronjob type thing it's up to you to wrap your script with something that will log the error. My cronjobs normally end up looking likeTaskWrapper('some job') do#work hereendand elsewheredef TaskWrapperbeginyieldrescue Exception => ex#do something with the exceptionraiseendendI use rescue Exception because for once I think it's appropriate that things like SyntaxError are caught so that I can be notified about themFor the sinatra (or even the rails case) you could write a rack middleware that would look something likeclass ErrorNotifierdef initialize(app)@app = appenddef call(env)begin@app.call(env)rescue Exception => ex#do something with the exceptionraiseendendendYou could also render an error message if you want to override that.You might also be interested in the exception handling stuff described at http://blog.plataformatec.com.br/2012/01/my-five- favorite-hidden-features-in- rails-3-2/ Fred
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/68616ea1-d09e-4b2b-a8b2-8e844fbae616%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home