module Halt

An extension to ActionController which enables standard error handling using ActionView and translations.

@api public @example

class ApplicationController < ActionController::Base
  include Pundit
  include Halt

  halt ActiveRecord::RecordNotFound, with: :not_found
  halt Pundit::NotAuthorizedError, with: :unauthorized
end

Constants

VERSION

Public Instance Methods

halt(exception, with: :server_error) click to toggle source
# File lib/halt.rb, line 31
def halt(exception, with: :server_error)
  halted[exception] = with
  rescue_from exception, with: :_handle_exception
end

Private Instance Methods

_handle_exception(exception) click to toggle source
# File lib/halt.rb, line 48
def _handle_exception(exception)
  Rails.logger.debug exception.message
  halt halted[exception.class], exception: exception
end