Module: TbCore::ErrorHandling

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/concerns/tb_core/error_handling.rb

Instance Method Summary collapse

Instance Method Details

#do_error_response(error) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/concerns/tb_core/error_handling.rb', line 23

def do_error_response(error)
  respond_to do |format|
    format.json { render json: { errors: error.message }, status: error.code }
    format.xml { render xml: { errors: error.message }, status: error.code }
    format.all do
      @error = error
      render template: error.template,
             layout: nil,
             formats: [:html],
             status: error.code,
             content_type: 'text/html'
    end
  end
end

#handle_record_not_found(error) ⇒ Object



38
39
40
41
# File 'app/controllers/concerns/tb_core/error_handling.rb', line 38

def handle_record_not_found(error)
  error = Spud::NotFoundError.new('record')
  handle_request_error(error)
end

#handle_request_error(error) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/concerns/tb_core/error_handling.rb', line 11

def handle_request_error(error)
  error.request_url = request.original_url
  error.template = template_for_request_error() if respond_to?(:template_for_request_error, true)

  if error.is_a?(Spud::UnauthorizedError) && request.format.html?
    redirect_to()
    return false
  end

  do_error_response(error)
end

#handle_unknown_format_error(error) ⇒ Object



43
44
45
46
# File 'app/controllers/concerns/tb_core/error_handling.rb', line 43

def handle_unknown_format_error(error)
  error = Spud::NotFoundError.new()
  handle_request_error(error)
end