Module: Roda::RodaPlugins::StatusHandler

Defined in:
lib/roda/plugins/status_handler.rb

Overview

The status_handler plugin adds a status_handler method which sets a block that is called whenever a response with the relevant response code with an empty body would be returned.

This plugin does not support providing the blocks with the plugin call; you must provide them to status_handler calls afterwards:

plugin :status_handler

status_handler(403) do
  "You are forbidden from seeing that!"
end

status_handler(404) do
  "Where did it go?"
end

status_handler(405, keep_headers: ['Accept']) do
  "Use a different method!"
end

Before a block is called, any existing headers on the response will be cleared, unless the :keep_headers option is used. If the :keep_headers option is used, the value should be an array, and only the headers listed in the array will be kept.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



35
36
37
# File 'lib/roda/plugins/status_handler.rb', line 35

def self.configure(app)
  app.opts[:status_handler] ||= {}
end