Sha256: 61f55aa526c0056ee3382959172438b13787115e810ee1622efe899ad4d696fb
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
module Customs module RescueTraffic def self.included base base.rescue_from CanCan::AccessDenied, with: proc{|e| rescue_exception_with e, :access_denied } base.rescue_from ActionController::UnknownFormat, with: proc{|e| rescue_exception_with e, :not_acceptable } if defined? ActionController::UnknownFormat base.rescue_from ActiveRecord::RecordNotFound, with: proc{|e| rescue_exception_with e, :not_found } if defined? ActiveRecord::RecordNotFound base.rescue_from ActiveRecord::RecordInvalid , with: proc{|e| rescue_exception_with e, :unprocessable } if defined? ActiveRecord::RecordInvalid base.rescue_from Mongoid::Errors::DocumentNotFound, with: proc{|e| rescue_exception_with e, :not_found } if defined? Mongoid::Errors base.rescue_from Mongoid::Errors::Validations , with: proc{|e| rescue_exception_with e, :unprocessable } if defined? Mongoid::Errors end def rescue_exception_with exception, status_method if respond_to?(:logger) && logger logger.info "[Customs] Rescuing from #{ exception.class } with :#{ status_method }" end send status_method end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
customs-1.1.0 | lib/customs/rescue_traffic.rb |