Module: Renderror::AutoRescue::ClassMethods

Defined in:
lib/renderror/auto_rescue.rb

Instance Method Summary collapse

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_requestObject



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

#rescue_cancanObject



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

#rescue_conflictObject



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_documentObject



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

#rescue_not_foundObject



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