Class: ExceptionNo::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app, notifier) ⇒ Middleware

Returns a new instance of Middleware.



57
58
59
60
# File 'lib/exception_no.rb', line 57

def initialize(app, notifier)
  @app = app
  @notifier = notifier
end

Instance Method Details

#call(env) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/exception_no.rb', line 62

def call(env)
  begin
    @app.call(env)
  rescue Exception => e
    @notifier.notify(e, body: extract_env(env))

    raise e
  end
end

#extract_env(env) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/exception_no.rb', line 72

def extract_env(env)
  req = Rack::Request.new(env)

  parts = []

  parts << "#{req.request_method} #{req.url}"
  parts << "User-Agent: #{req.user_agent}" if req.user_agent
  parts << "Referrer: #{req.referrer}" if req.referrer
  parts << "Cookie: #{req.env["HTTP_COOKIE"]}" if req.cookies.size > 0

  parts.join("\n")
end