Class: Utopia::MailExceptions

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

Overview

Catches all exceptions raised from the app it wraps and sends a useful email with the exception, stacktrace, and contents of the environment.

Constant Summary collapse

LOCAL_SMTP =

A basic local non-authenticated SMTP server.

[:smtp, {
  :address => "localhost",
  :port => 25,
  :enable_starttls_auto => false
}]

Instance Method Summary collapse

Constructor Details

#initialize(app, config = {}) ⇒ MailExceptions

Returns a new instance of MailExceptions.



34
35
36
37
38
39
40
41
42
43
# File 'lib/utopia/mail_exceptions.rb', line 34

def initialize(app, config = {})
  @app = app
  
  @to = config[:to] || "postmaster"
  @from = config.fetch(:from) {(ENV['USER'] || 'rack') + "@localhost"}
  @subject = config[:subject] || '%{exception} [PID %{pid} : %{cwd}]'
  @delivery_method = config.fetch(:delivery_method, LOCAL_SMTP)
  
  @dump_environment = config.fetch(:dump_environment, false)
end

Instance Method Details

#call(env) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/utopia/mail_exceptions.rb', line 45

def call(env)
  begin
    return @app.call(env)
  rescue => exception
    send_notification exception, env
    
    raise
  end
end