module Outpost::Controller::CustomErrors

Constants

NOT_FOUND_ERROR_CLASSES

Private Instance Methods

render_error(status, e=StandardError, template_prefix="outpost/") click to toggle source

We don't want this to be considered an action method, so it's private

# File lib/outpost/controller/custom_errors.rb, line 30
def render_error(status, e=StandardError, template_prefix="outpost/")
  response.status = status

  if Rails.application.config.consider_all_requests_local
    raise e
  else
    respond_to do |format|
      format.html do
        render(
          :template   => "#{template_prefix}errors/error_#{status}",
          :layout     => "#{template_prefix}application",
          :status     => status,
          :locals     => { error: e }
        )
      end

      format.xml do
        render xml: {
          :error    => response.message,
          :code     => status
        }, status: status
      end

      format.json do
        render json: {
          :error    => response.message,
          :code     => status
        }, status: status
      end

      format.text do
        render(
          :text     => "#{status} - #{response.message}",
          :status   => status
        )
      end

      format.any do
        head status
      end
    end
  end
end