Module: Carbonyte::Concerns::Rescuable

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/carbonyte/concerns/rescuable.rb

Overview

The Rescuable concern rescues controllers from bubbling up the most common exceptions and provides a uniformed response body in case of such errors.

Instance Method Summary collapse

Instance Method Details

#rescue_with_handler(exception) ⇒ Object

Upon rescuing an exception, stores that exception in RequestStore for later logging

Parameters:

  • exception (StandardError)

    the rescued exception



24
25
26
27
# File 'app/controllers/carbonyte/concerns/rescuable.rb', line 24

def rescue_with_handler(exception)
  RequestStore.store[:rescued_exception] = exception
  super
end

#route_not_foundObject

This is a special case



30
31
32
33
34
35
36
37
38
# File 'app/controllers/carbonyte/concerns/rescuable.rb', line 30

def route_not_found
  payload = {
    code: 'RoutingError',
    source: request.path,
    title: 'Route not found',
    detail: "No route matches #{request.path}"
  }
  render json: serialized_errors(payload), status: :not_found
end