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



1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
# File 'lib/amazon/aws.rb', line 1197

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.
  #
  unless Amazon::AWS::Error.const_defined?( err_class )
    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