Class: Hoodoo::ErrorDescriptions::DomainDescriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/hoodoo/errors/error_descriptions.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ DomainDescriptions

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.



186
187
188
189
# File 'lib/hoodoo/errors/error_descriptions.rb', line 186

def initialize( domain )
  @domain       = domain
  @descriptions = {}
end

Instance Attribute Details

#descriptionsObject (readonly)

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



179
180
181
# File 'lib/hoodoo/errors/error_descriptions.rb', line 179

def descriptions
  @descriptions
end

#domainObject (readonly)

Domain name for this description instance (string).



174
175
176
# File 'lib/hoodoo/errors/error_descriptions.rb', line 174

def domain
  @domain
end

Instance Method Details

#error(name, options) ⇒ Object

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.



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/hoodoo/errors/error_descriptions.rb', line 214

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