Module: JSONAPI::ActsAsResourceController::ClassMethods

Defined in:
lib/jsonapi/acts_as_resource_controller.rb

Overview

Pass in a methods or a block to be run when an exception is caught that is not a JSONAPI::Exceptions::Error Useful for additional logging or notification configuration that would normally depend on rails catching and rendering an exception. Ignores whitelist exceptions from config

Instance Method Summary collapse

Instance Method Details

#on_server_error(*args, &callback_block) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/jsonapi/acts_as_resource_controller.rb', line 315

def on_server_error(*args, &callback_block)
  callbacks ||= []

  if callback_block
    callbacks << callback_block
  end

  method_callbacks = args.map do |method|
    ->(error) do
      if self.respond_to? method
        send(method, error)
      else
        Rails.logger.warn("#{method} not defined on #{self}, skipping error callback")
      end
    end
  end.compact
  callbacks += method_callbacks
  self.class_variable_set :@@server_error_callbacks, callbacks
end