Exception: YieldStarClient::ServerError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/yield_star_client/errors.rb

Overview

Represents a server-side error returned by the YieldStar web service.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code = nil) ⇒ ServerError

Creates a new error object.

Parameters:

  • message (String) (defaults to: nil)

    the error message. If no message is supplied, the object’s class name will be used as the message.

  • code (String) (defaults to: nil)

    the error code



11
12
13
14
# File 'lib/yield_star_client/errors.rb', line 11

def initialize(message=nil, code=nil)
  super(message)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/yield_star_client/errors.rb', line 4

def code
  @code
end

Class Method Details

.translate_fault(soap_error) ⇒ YieldStarClient::ServerError

Translates a soap fault into the appropriate YieldStarClient error.

Parameters:

  • soap_error (Savon::SOAP::Fault)

    the error object raised by the soap client

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yield_star_client/errors.rb', line 20

def self.translate_fault(soap_error)
  fault = soap_error.to_hash[:fault]

  # set up defaults
  error_class = YieldStarClient::ServerError
  fault_detail = {:code => fault[:faultcode], :message => fault[:faultstring]}

  if detail = fault[:detail]
    if detail.has_key?(:authentication_fault)
      error_class = YieldStarClient::AuthenticationError
      fault_detail = detail[:authentication_fault]
    elsif detail.has_key?(:operation_fault)
      error_class = YieldStarClient::OperationError
      fault_detail = detail[:operation_fault]
    elsif detail.has_key?(:internal_error_fault)
      error_class = YieldStarClient::InternalError
      fault_detail = detail[:internal_error_fault]
    end
  end

  error_class.new(fault_detail[:message], fault_detail[:code])
end