Guest User

Untitled

a guest
May 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'sinatra/base'
  2. module Sinatra
  3. # module to catch Sinatra errors and send a email
  4. module ExceptionMailer
  5. def initialize(app)
  6. @app = app
  7. # set parameters here..
  8. yield self if block_given?
  9. end
  10.  
  11. def call(env)
  12. status, headers, body =
  13. begin
  14. @app.call(env)
  15. rescue => error_raised
  16. # TODO don't allow exceptions from send_notification to
  17. # propogate
  18. send_notification error_raised, env
  19. raise
  20. end
  21. [status, headers, body]
  22. end
  23.  
  24. private
  25.  
  26. def send_notification(exception, env)
  27. puts "SENDING NOTIFICATION for :#{exception}"
  28. end
  29. end
  30.  
  31. register ExceptionMailer
  32. end
Add Comment
Please, Sign In to add comment