class JsonapiErrorsHandler::ErrorMapper

Maps any of the given error classes into the serializable errors from the predefined collection

Attributes

mapped_errors[R]

Public Class Methods

descendant_of_predefined?(error) click to toggle source
# File lib/jsonapi_errors_handler/error_mapper.rb, line 33
def self.descendant_of_predefined?(error)
  return false if error.is_a?(Class)

  error.class < JsonapiErrorsHandler::Errors::StandardError
end
map_errors!(errors_hash = {}) click to toggle source
# File lib/jsonapi_errors_handler/error_mapper.rb, line 14
def self.map_errors!(errors_hash = {})
  @mapped_errors.merge!(errors_hash)
end
mapped_error(error) click to toggle source
# File lib/jsonapi_errors_handler/error_mapper.rb, line 22
def self.mapped_error(error)
  return error if descendant_of_predefined?(error)

  error_class = error.is_a?(Class) ? error.to_s : error.class.name
  root_class = error_class.split('::').first
  mapped = mapped_errors[error_class] || mapped_errors[root_class]
  return unless mapped

  Object.const_get(mapped).new
end
mapped_error?(error_klass) click to toggle source
# File lib/jsonapi_errors_handler/error_mapper.rb, line 18
def self.mapped_error?(error_klass)
  mapped_errors.key?(error_klass)
end