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



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/jsonapi/acts_as_resource_controller.rb', line 298

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