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

#handle_error(exception, layout: "error", title: "Error - Application", format: nil) ⇒ Object

Handles an error in the application.

Parameters:

  • exception (Hash|Exception)

    The exception to handle.

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

    The layout to use to render the error. The @error variable will be exposed.

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

    The title to set in case of custom errors.

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

    The format of the response.



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

def handle_error(exception, layout: "error", title: "Error - Application", format: nil)
  @error =
    if exception.is_a?(Lazier::Exceptions::Debug)
      {status: 503, title: "Debug", error: exception.message, exception: exception}
    elsif exception.is_a?(::Hash)
      exception.reverse_merge({title: title})
    else
      {status: 500, title: "Error - #{exception.class}", error: exception.message, exception: exception}
    end

  send_or_render_error(layout, format)
end