UtopiaSourceUtopiaExceptionsMailer

class Mailer

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.

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_environment: false)

Implementation

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

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_environment.freeze
	
	super
end

def call(env)

Report application exceptions by email before reraising them.

Signature

parameter env Hash

The Rack environment.

returns Array

The application response.

Implementation

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