Module: Amazon::AWS::Error

Defined in:
lib/amazon/aws.rb

Overview

All dynamically generated exceptions occur within this namespace.

Defined Under Namespace

Classes: AWSError

Class Method Summary collapse

Class Method Details

.exception(xml) ⇒ Object



884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
# File 'lib/amazon/aws.rb', line 884

def Error.exception(xml)
  err_class = xml.elements['Code'].text.sub( /^AWS.*\./, '' )
  err_msg = xml.elements['Message'].text

  # Dynamically define a new exception class for this class of error,

  # unless it already exists.

  #

  # Note that Ruby 1.9's Module.const_defined? needs a second parameter

  # of *false*, or it will also search AWSError's ancestors.

  #

  cd_params = [ err_class ]
  cd_params << false if RUBY_VERSION >= '1.9.0'

  unless Amazon::AWS::Error.const_defined?( *cd_params )
    Amazon::AWS::Error.const_set( err_class, Class.new( AWSError ) )
  end

  # Generate and return a new exception from the relevant class.

  #

  Amazon::AWS::Error.const_get( err_class ).new( err_msg )
end