Module: Renderror::AutoRescue::ClassMethods

Defined in:
lib/renderror/auto_rescue.rb

Instance Method Summary collapse

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_requestObject



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.message)]
    )
  end
end

#rescue_cancanObject



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.message)]
    )
  end
end

#rescue_invalid_documentObject



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.message)]
    )
  end
end

#rescue_not_foundObject



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.message)]
    )
  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