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
- ATTACHMENT_SIZE_LIMIT =
64*1024
- SENSITIVE_FIELD =
/authorization|cookie|credential|password|private[_-]?key|referer|referrer|secret|session|token|variables|api[_-]?key/i- REDACTED =
"[REDACTED]".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_body: false, dump_environment: false, attachment_size_limit: ATTACHMENT_SIZE_LIMIT, redact: SENSITIVE_FIELD) ⇒ Mailer
constructor
A new instance of Mailer.
Constructor Details
#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) ⇒ Mailer
Returns a new instance of Mailer.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/utopia/exceptions/mailer.rb', line 41 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() @redact = redact if @attachment_size_limit < 0 raise ArgumentError, "attachment_size_limit must not be negative!" end end |
Instance Method Details
#call(request) ⇒ Object
Report application exceptions by email before returning an error response.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/utopia/exceptions/mailer.rb', line 78 def call(request) begin return @delegate.call(request) rescue *APPLICATION_ERRORS => exception request.exception = exception send_notification exception, request raise end end |
#freeze ⇒ Object
Freeze this object and its internal state.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/utopia/exceptions/mailer.rb', line 60 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 |