Class: Utopia::Exceptions::Mailer
- Inherits:
-
Protocol::HTTP::Middleware
- Object
- Protocol::HTTP::Middleware
- Utopia::Exceptions::Mailer
- Defined in:
- lib/utopia/exceptions/mailer.rb
Overview
A middleware which catches application exceptions and sends an email containing the exception, backtrace, request, and application state.
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(request) ⇒ Object
Report application exceptions by email before returning an error response.
-
#freeze ⇒ Object
Freeze this object and its internal state.
-
#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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/utopia/exceptions/mailer.rb', line 32 def initialize(app, to: "postmaster", from: DEFAULT_FROM, subject: DEFAULT_SUBJECT, delivery_method: LOCAL_SMTP, dump_environment: false) super(app) @to = to @from = from @subject = subject @delivery_method = delivery_method @dump_environment = dump_environment end |
Instance Method Details
#call(request) ⇒ Object
Report application exceptions by email before returning an error response.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/utopia/exceptions/mailer.rb', line 59 def call(request) begin return @delegate.call(request) rescue => exception request.exception = exception send_notification exception, request raise end end |
#freeze ⇒ Object
Freeze this object and its internal state.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/utopia/exceptions/mailer.rb', line 44 def freeze return self if frozen? @to.freeze @from.freeze @subject.freeze @delivery_method.freeze @dump_environment.freeze super end |