Module: Ballast::Concerns::ErrorsHandling

Extended by:
ActiveSupport::Concern
Defined in:
lib/ballast/concerns/errors_handling.rb

Overview

A concern to handle errors. It requires the Ajax concern.

Instance Method Summary (collapse)

Instance Method Details

- (Object) handle_error(exception = nil, layout = "error", title = "Error - Application", format = nil)

Handles an error in the application.

Parameters:

  • exception (Hash|Exception) (defaults to: nil)

    The exception to handle.

  • layout (String) (defaults to: "error")

    The layout to use to render the error.

  • title (String) (defaults to: "Error - Application")

    The title to set in case of custom errors.

  • format (String|Symbol) (defaults to: nil)

    The format of the response.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ballast/concerns/errors_handling.rb', line 18

def handle_error(exception = nil, layout = "error", title = "Error - Application", format = nil)
  @error ||= exception

  if @error.is_a?(Lazier::Exceptions::Debug) then
    @error_title = "Debug"
    @error_code = 503
  elsif @error.is_a?(Hash) then
    @error_title = @error[:title] || title
    @error_code = @error[:status]
    @error_message = @error[:error]
  else
    @error_title = "Error - #{@error.class.to_s}"
    @error_code = 500
  end

  send_or_render_error(layout, format)
end