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_conflict ⇒ Object
- #rescue_invalid_document ⇒ Object
- #rescue_not_found ⇒ Object
- #sanitized_exceptions(exception_list) ⇒ Object
Instance Method Details
#renderror_auto_rescue(*exceptions) ⇒ Object
10 11 12 13 14 |
# 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 ⇒ Object
20 21 22 23 24 25 26 |
# 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.)] ) end end |
#rescue_cancan ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/renderror/auto_rescue.rb', line 45 def rescue_cancan rescue_from CanCan::AccessDenied do |exception| render_errors( [Renderror::Forbidden.new(detail: exception.)] ) end end |
#rescue_conflict ⇒ Object
53 54 55 56 57 |
# 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 ⇒ Object
36 37 38 39 40 41 42 43 |
# 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.)] ) end end |
#rescue_not_found ⇒ Object
28 29 30 31 32 33 34 |
# 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.)] ) end end |
#sanitized_exceptions(exception_list) ⇒ Object
16 17 18 |
# File 'lib/renderror/auto_rescue.rb', line 16 def sanitized_exceptions(exception_list) exception_list.select { |e| PERMITTED_EXCEPTIONS.include? e } end |