Strelka::App::Errors::

ClassMethods

module

Class-level functionality

Attributes

status_handlers[R]

The registered status handler callbacks, keyed by Integer Ranges of status codes to which they apply

Public Instance Methods

anchor
inherited( subclass )

Extension callback – add instance variables to extending objects.

# File lib/strelka/app/errors.rb, line 102
def inherited( subclass )
        super
        subclass.instance_variable_set( :@status_handlers, @status_handlers.dup )
end
anchor
on_status( range=DEFAULT_HANDLER_STATUS_RANGE, template=nil, &block )

Register a callback for responses whose status code is within the specified range. Range can either be a single integer HTTP status code, or a Range of the same (e.g., 400..499) for all statuses with that range.

If no range is specified, any of the HTTP error statuses will invoke the callback.

The block will be called with the response object (a subclass of Mongrel2::Response appropriate for the request type), and a hash of status info that will at least contain the following keys:

:status

the HTTP status code that was passed to Strelka::ResponseHelpers#finish_with

:message

the message string that was passed to Strelka::ResponseHelpers#finish_with

# File lib/strelka/app/errors.rb, line 122
def on_status( range=DEFAULT_HANDLER_STATUS_RANGE, template=nil, &block )
        range = Range.new( range, range ) unless range.is_a?( Range )
        methodname = "for_status_%s" % [ range.begin, range.end ].uniq.join('_to_')

        if template
                raise ArgumentError, "template-style callbacks don't take a block" if block
                raise ScriptError, "template-style callbacks require the :templating plugin" unless
                        self.respond_to?( :templates )

                block = Proc.new {|*| template }
        end

        define_method( methodname, &block )

        self.status_handlers[ range ] = instance_method( methodname )
end