Created
June 21, 2011 14:06
-
-
Save thibaudgg/1037932 to your computer and use it in GitHub Desktop.
Custom Goliath Rack middleware for HoptoadNotifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Goliath | |
| module Rack | |
| class Hoptoad | |
| include Goliath::Constants | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| response = @app.call(env) | |
| if env[RACK_EXCEPTION] | |
| HoptoadNotifier.notify(env[RACK_EXCEPTION]) | |
| end | |
| response | |
| rescue Exception => e | |
| HoptoadNotifier.notify(e) | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'goliath' | |
| require 'hoptoad_notifier' | |
| HoptoadNotifier.configure do |config| | |
| config.api_key = 'my_api_key' | |
| end | |
| require 'hoptoad' # custom middleware | |
| class Server < Goliath::API | |
| use Goliath::Rack::Hoptoad | |
| def response(env) | |
| raise 'Notify hoptoad' | |
| [200, {}, "ouch"] | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for that one!