class Rack::EmailExceptions

Public Class Methods

new(app, prefix, email) click to toggle source

Store the prefix to use in the email in addition to the next application.

# File lib/rack/email_exceptions.rb, line 11
def initialize(app, prefix, email)
  @app = app
  @prefix = prefix
  @email = email
end

Public Instance Methods

call(env) click to toggle source

Rescue any errors raised by calling the next application, and if there is an error, email about it before reraising it.

# File lib/rack/email_exceptions.rb, line 19
    def call(env)
      @app.call(env)
    rescue StandardError, ScriptError => e
      body = <<END
From: #{@email}\r
To: #{@email}\r
Subject: [#{@prefix}] Unhandled Error Raised by Rack App or Middleware\r
\r
\r
Error: #{e.class}: #{e.message}

Backtrace:

#{e.backtrace.join("\n")}

ENV:

#{env.map{|k, v| "#{k.inspect} => #{v.inspect}"}.sort.join("\n")}
END

      Net::SMTP.start('127.0.0.1'){|s| s.send_message(body, @email, @email)}

      raise
    end