class Mailer < Protocol::HTTP::Middleware
- Inherits from
Protocol::HTTP::Middleware
A middleware which catches application exceptions and sends an email containing the exception, backtrace, request, and application state.
Definitions
LOCAL_SMTP = [...]
A basic local non-authenticated SMTP server.
Implementation
LOCAL_SMTP = [:smtp, {
:address => "localhost",
:port => 25,
:enable_starttls_auto => false
}]
def initialize(app, to: "postmaster", from: DEFAULT_FROM, subject: DEFAULT_SUBJECT, delivery_method: LOCAL_SMTP, dump_body: false, dump_environment: false, attachment_size_limit: ATTACHMENT_SIZE_LIMIT, redact: SENSITIVE_FIELD)
Implementation
def initialize(app, to: "postmaster", from: DEFAULT_FROM, subject: DEFAULT_SUBJECT, delivery_method: LOCAL_SMTP, dump_body: false, dump_environment: false, attachment_size_limit: ATTACHMENT_SIZE_LIMIT, redact: SENSITIVE_FIELD)
super(app)
@to = to
@from = from
@subject = subject
@delivery_method = delivery_method
@dump_body = dump_body
@dump_environment = dump_environment
@attachment_size_limit = Integer(attachment_size_limit)
@redact = redact
if @attachment_size_limit < 0
raise ArgumentError, "attachment_size_limit must not be negative!"
end
end
def freeze
Freeze this object and its internal state.
Signature
-
returns
self This object.
Implementation
def freeze
return self if frozen?
@to.freeze
@from.freeze
@subject.freeze
@delivery_method.freeze
@dump_body.freeze
@dump_environment.freeze
@attachment_size_limit.freeze
@redact.freeze
super
end
def call(request)
Report application exceptions by email before returning an error response.
Signature
-
parameter
requestUtopia::Request The request.
-
returns
Protocol::HTTP::Response The application response or a generated error response.
Implementation
def call(request)
begin
return @delegate.call(request)
rescue *APPLICATION_ERRORS => exception
request.exception = exception
send_notification exception, request
raise
end
end