Module: WithErrorsFilter

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/with_errors_filter.rb

Instance Method Summary collapse

Instance Method Details

#catch_exceptionsObject



9
10
11
12
13
# File 'app/controllers/concerns/with_errors_filter.rb', line 9

def catch_exceptions
  yield
rescue ActiveRecord::RecordInvalid => e
  render! e.record.errors
end

#catch_unhandled_errors(e) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/concerns/with_errors_filter.rb', line 15

def catch_unhandled_errors(e)
  summary = {
      errors: {
          :exception => "#{e.class.name} : #{e.message}"
      }
  }
  summary[:trace] = e.backtrace[0, 10] if Rails.env.development?

  render json: summary, status: :internal_server_error
end