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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/jsonapi/acts_as_resource_controller.rb', line 257 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 |