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.



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

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).



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

def descriptions
  @descriptions
end

#domainObject (readonly)

Domain name for this description instance (string).



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

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.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# 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