class Aws::AwsError

Exception class to signal any Amazon errors. All errors occuring during calls to Amazon's web services raise this type of error. Attribute inherited by RuntimeError:

message    - the text of the error, generally as returned by AWS in its XML response.

Attributes

errors[R]

either an array of errors where each item is itself an array of [code, message]), or an error string if the error was raised manually, as in AwsError.new('err_text')

http_code[R]

Response HTTP error code

request_data[R]

Raw request text data to AWS

request_id[R]

Request id (if exists)

response[R]

Public Class Methods

new(errors=nil, http_code=nil, request_id=nil, request_data=nil, response=nil) click to toggle source
Calls superclass method
# File lib/awsbase/errors.rb, line 28
def initialize(errors=nil, http_code=nil, request_id=nil, request_data=nil, response=nil)
  @errors       = errors
  @request_id   = request_id
  @http_code    = http_code
  @request_data = request_data
  @response     = response
  msg           = @errors.is_a?(Array) ? @errors.map { |code, m| "#{code}: #{m}" }.join("; ") : @errors.to_s
  msg += "\nREQUEST=#{@request_data} " unless @request_data.nil?
  msg += "\nREQUEST ID=#{@request_id} " unless @request_id.nil?
  super(msg)
end
on_aws_exception(aws, options={:raise=>true, :log=>true}) click to toggle source

Generic handler for AwsErrors. aws is the Aws::S3, Aws::EC2, or Aws::SQS object that caused the exception (it must provide last_request and last_response). Supported boolean options are:

  • :log print a message into the log using aws.logger to access the Logger

  • :puts do a “puts” of the error

  • :raise re-raise the error after logging

# File lib/awsbase/errors.rb, line 61
def self.on_aws_exception(aws, options={:raise=>true, :log=>true})
  # Only log & notify if not user error
  if !options[:raise] || system_error?($!)
    error_text = "#{$!.inspect}\n#{$@}.join('\n')}"
    puts error_text if options[:puts]
    # Log the error
    if options[:log]
      request   = aws.last_request ? aws.last_request.path : '-none-'
      response  = aws.last_response ? "#{aws.last_response.code} -- #{aws.last_response.message} -- #{aws.last_response.body}" : '-none-'
      @response = response
      aws.logger.error error_text
      aws.logger.error "Request was:  #{request}"
      aws.logger.error "Response was: #{response}"
    end
  end
  raise if options[:raise] # re-raise an exception
  return nil
end
system_error?(e) click to toggle source

True if e is an AWS system error, i.e. something that is for sure not the caller's fault. Used to force logging.

# File lib/awsbase/errors.rb, line 82
def self.system_error?(e)
  !e.is_a?(self) || e.message =~ /InternalError|InsufficientInstanceCapacity|Unavailable/
end

Public Instance Methods

include?(pattern_or_string) click to toggle source

Does any of the error messages include the regexp pattern? Used to determine whether to retry request.

# File lib/awsbase/errors.rb, line 42
def include?(pattern_or_string)
  if pattern_or_string.is_a?(String)
    puts 'convert to pattern'
    pattern_or_string = /#{pattern_or_string}/
  end
  if @errors.is_a?(Array)
    @errors.each { |code, msg| return true if code =~ pattern_or_string }
  else
    return true if @errors_str =~ pattern_or_string
  end
  false
end