Module: Renderror::AutoRescue::ClassMethods
- Defined in:
- lib/renderror/auto_rescue.rb
Instance Method Summary collapse
- #renderror_auto_rescue(*exceptions) ⇒ Object
- #rescue_bad_request ⇒ Object
- #rescue_cancan ⇒ Object
- #rescue_invalid_document ⇒ Object
- #rescue_not_found ⇒ Object
- #sanitized_exceptions(exception_list) ⇒ Object
Instance Method Details
#renderror_auto_rescue(*exceptions) ⇒ Object
13 14 15 16 17 |
# File 'lib/renderror/auto_rescue.rb', line 13 def renderror_auto_rescue(*exceptions) sanitized_exceptions(exceptions).each do |e| send("rescue_#{e}") end end |
#rescue_bad_request ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/renderror/auto_rescue.rb', line 23 def rescue_bad_request rescue_from ActionController::BadRequest do |exception| render_errors( [Renderror::BadRequest.new(detail: exception.)] ) end end |
#rescue_cancan ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/renderror/auto_rescue.rb', line 48 def rescue_cancan rescue_from CanCan::AccessDenied do |exception| render_errors( [Renderror::Forbidden.new(detail: exception.)] ) end end |
#rescue_invalid_document ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/renderror/auto_rescue.rb', line 39 def rescue_invalid_document rescue_from ActiveModelSerializers::Adapter:: JsonApi::Deserialization::InvalidDocument do |exception| render_errors( [Renderror::BadRequest.new(detail: exception.)] ) end end |
#rescue_not_found ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/renderror/auto_rescue.rb', line 31 def rescue_not_found rescue_from ActiveRecord::RecordNotFound do |exception| render_errors( [Renderror::NotFound.new(detail: exception.)] ) end end |
#sanitized_exceptions(exception_list) ⇒ Object
19 20 21 |
# File 'lib/renderror/auto_rescue.rb', line 19 def sanitized_exceptions(exception_list) exception_list.select { |e| PERMITTED_EXCEPTIONS.include? e } end |