Class: CustosNotifier::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/custos_notifier/rack.rb

Overview

Simple middleware for handling raised exceptions in Rack applications Example:

class MyApp
  def call(env)
    raise "my exception"
  end
end

CustosNotifier.configure do |config|
  config.url      = "foo.blah.bar"
  config.project  = "awsomeSite"
  config.stage    = "production"
  config.api_key  = "secret"
end

use CustosNotifier::Rack
run MyApp

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



22
23
24
# File 'lib/custos_notifier/rack.rb', line 22

def initialize(app)
  @app = app  
end

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/custos_notifier/rack.rb', line 27

def call(env)
  begin
    @app.call(env)
  rescue Exception => raised
    CustosNotifier.notify(raised, :rack_env => env)
    if rails_3_app?
      if rails_3_not_dev?
        [500, {"Content-Type" => "text/html"}, File.read(File.join Rails.root, "public/500.html")]
      else
        raise
      end
    else
      [500, {"Content-Type" => "text/html"},"Something went wrong"]
    end
  end
end