Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Monkey patch exception logging into async_sinatra
  2. #
  3. # This is a workaround for the lack of error handling/logging on asynchronous
  4. # requests (e.g. aget, apost) when using async_sinatra 0.5.0, sinatra 1.2.6,
  5. # thin 1.2.11, and rack 1.3.0.
  6. #
  7. # See http://stackoverflow.com/questions/6427033/how-do-i-log-asynchronous-thinsinatrarack-requests
  8. module Sinatra::Async
  9.         alias :oldaroute :aroute
  10.  
  11.         def aroute *args, &block
  12.                 oldaroute(*args) { |*a|
  13.                         begin
  14.                                 block.call *a
  15.                         rescue Exception => e
  16.                                 status 500
  17.                                 puts "Asynchronous exception:"
  18.                                 puts "#{e.class} - #{e.message}: \n #{e.backtrace.join("\n ")}\n"
  19.                                 ahalt e
  20.                         end
  21.                 }
  22.         end
  23. end