Class: Utopia::Exceptions::Mailer
- Inherits:
-
Object
- Object
- Utopia::Exceptions::Mailer
- Defined in:
- lib/utopia/exceptions/mailer.rb
Overview
A middleware which 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 }]
- DEFAULT_FROM =
(ENV['USER'] || 'utopia').freeze
- DEFAULT_SUBJECT =
'%{exception} [PID %{pid} : %{cwd}]'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
- #freeze ⇒ Object
-
#initialize(app, to: "postmaster", from: DEFAULT_FROM, subject: DEFAULT_SUBJECT, delivery_method: LOCAL_SMTP, dump_environment: false) ⇒ Mailer
constructor
A new instance of Mailer.
Constructor Details
#initialize(app, to: "postmaster", from: DEFAULT_FROM, subject: DEFAULT_SUBJECT, delivery_method: LOCAL_SMTP, dump_environment: false) ⇒ Mailer
Returns a new instance of Mailer.
28 29 30 31 32 33 34 35 36 |
# File 'lib/utopia/exceptions/mailer.rb', line 28 def initialize(app, to: "postmaster", from: DEFAULT_FROM, subject: DEFAULT_SUBJECT, delivery_method: LOCAL_SMTP, dump_environment: false) @app = app @to = to @from = from @subject = subject @delivery_method = delivery_method @dump_environment = dump_environment end |
Instance Method Details
#call(env) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/utopia/exceptions/mailer.rb', line 50 def call(env) begin return @app.call(env) rescue => exception send_notification exception, env raise end end |
#freeze ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/utopia/exceptions/mailer.rb', line 38 def freeze return self if frozen? @to.freeze @from.freeze @subject.freeze @delivery_method.freeze @dump_environment.freeze super end |