class Hoodoo::ErrorDescriptions::DomainDescriptions

Contain a description of errors for a particular domain, where the domain is a grouping string such as “platform”, “generic”, or a short service name. Usually driven via Hoodoo::ErrorDescriptions, not directly.

Attributes

descriptions[R]

Hash of all descriptions, keyed by full error code, with options hash data as values (see error for details).

domain[R]

Domain name for this description instance (string).

Public Class Methods

new( domain ) click to toggle source

Initialize a new instance for the given domain.

domain

The domain string - for most service-based callers, usually a short service name like members or transactions.

# File lib/hoodoo/errors/error_descriptions.rb, line 185
def initialize( domain )
  @domain       = domain
  @descriptions = {}
end

Public Instance Methods

error( name, options ) click to toggle source

Describe an error.

name

The error name - the bit after the “.” in the code, e.g. invalid_parameters.

options

Options hash. See below.

The options hash contains symbol keys named as follows, with values as described:

:status

The integer or string HTTP status code to be associated with this error

message

The en-nz language human-readable error message used for developers.

reference

Optional array of required named references. When errors are added (via Hoodoo::Errors#add_error) to a collection, required reference(s) from this array must be provided by the error-adding caller else an exception will be raised. This ensures correct, fully qualified error data is logged and sent to clients.

# File lib/hoodoo/errors/error_descriptions.rb, line 213
def error( name, options )
  options       = Hoodoo::Utilities.stringify( options )
  required_keys = [ 'status', 'message' ]

  reference              = options[ 'reference' ]
  options[ 'reference' ] = reference.map( &:to_s ) if reference.is_a?( ::Array )

  required_keys.each do | required_key |
    unless options.has_key?( required_key )
      raise "Error description options hash missing required key '#{ required_key }'"
    end
  end

  @descriptions[ "#{ @domain }.#{ name }" ] = options
end