module Renderror::AutoRescue::ClassMethods

Public Instance Methods

renderror_auto_rescue(*exceptions) click to toggle source
# File lib/renderror/auto_rescue.rb, line 10
def renderror_auto_rescue(*exceptions)
  sanitized_exceptions(exceptions).each do |e|
    send("rescue_#{e}")
  end
end
rescue_bad_request() click to toggle source
# File lib/renderror/auto_rescue.rb, line 20
def rescue_bad_request
  rescue_from ActionController::BadRequest do |exception|
    render_errors(
      [Renderror::BadRequest.new(detail: exception.message)]
    )
  end
end
rescue_cancan() click to toggle source
# File lib/renderror/auto_rescue.rb, line 45
def rescue_cancan
  rescue_from CanCan::AccessDenied do |exception|
    render_errors(
      [Renderror::Forbidden.new(detail: exception.message)]
    )
  end
end
rescue_conflict() click to toggle source
# File lib/renderror/auto_rescue.rb, line 53
def rescue_conflict
  rescue_from Renderror::Conflict do |exception|
    render_errors(exception)
  end
end
rescue_invalid_document() click to toggle source
# File lib/renderror/auto_rescue.rb, line 36
def rescue_invalid_document
  rescue_from ActiveModelSerializers::Adapter::
    JsonApi::Deserialization::InvalidDocument do |exception|
    render_errors(
      [Renderror::BadRequest.new(detail: exception.message)]
    )
  end
end
rescue_not_found() click to toggle source
# File lib/renderror/auto_rescue.rb, line 28
def rescue_not_found
  rescue_from ActiveRecord::RecordNotFound do |exception|
    render_errors(
      [Renderror::NotFound.new(detail: exception.message)]
    )
  end
end
sanitized_exceptions(exception_list) click to toggle source
# File lib/renderror/auto_rescue.rb, line 16
def sanitized_exceptions(exception_list)
  exception_list.select { |e| PERMITTED_EXCEPTIONS.include? e }
end