Exception: Aws::AwsError
- Defined in:
- lib/awsbase/right_awsbase.rb
Overview
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.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
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 ⇒ Object
readonly
Response HTTP error code.
-
#request_data ⇒ Object
readonly
Raw request text data to AWS.
-
#request_id ⇒ Object
readonly
Request id (if exists).
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.on_aws_exception(aws, options = {:raise=>true, :log=>true}) ⇒ Object
Generic handler for AwsErrors.
-
.system_error?(e) ⇒ Boolean
True if e is an AWS system error, i.e.
Instance Method Summary collapse
-
#include?(pattern) ⇒ Boolean
Does any of the error messages include the regexp
pattern
? Used to determine whether to retry request. -
#initialize(errors = nil, http_code = nil, request_id = nil, request_data = nil, response = nil) ⇒ AwsError
constructor
A new instance of AwsError.
Constructor Details
#initialize(errors = nil, http_code = nil, request_id = nil, request_data = nil, response = nil) ⇒ AwsError
Returns a new instance of AwsError.
565 566 567 568 569 570 571 572 573 574 |
# File 'lib/awsbase/right_awsbase.rb', line 565 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, msg| "#{code}: #{msg}"}.join("; ") : @errors.to_s msg += "\nREQUEST(#{@request_data})" unless @request_data.nil? super(msg) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
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')
552 553 554 |
# File 'lib/awsbase/right_awsbase.rb', line 552 def errors @errors end |
#http_code ⇒ Object (readonly)
Response HTTP error code
558 559 560 |
# File 'lib/awsbase/right_awsbase.rb', line 558 def http_code @http_code end |
#request_data ⇒ Object (readonly)
Raw request text data to AWS
561 562 563 |
# File 'lib/awsbase/right_awsbase.rb', line 561 def request_data @request_data end |
#request_id ⇒ Object (readonly)
Request id (if exists)
555 556 557 |
# File 'lib/awsbase/right_awsbase.rb', line 555 def request_id @request_id end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
563 564 565 |
# File 'lib/awsbase/right_awsbase.rb', line 563 def response @response end |
Class Method Details
.on_aws_exception(aws, options = {:raise=>true, :log=>true}) ⇒ Object
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
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/awsbase/right_awsbase.rb', line 593 def self.on_aws_exception(aws, ={:raise=>true, :log=>true}) # Only log & notify if not user error if ![:raise] || system_error?($!) error_text = "#{$!.inspect}\n#{$@}.join('\n')}" puts error_text if [:puts] # Log the error if [:log] request = aws.last_request ? aws.last_request.path : '-none-' response = aws.last_response ? "#{aws.last_response.code} -- #{aws.last_response.} -- #{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 [:raise] # re-raise an exception return nil end |
.system_error?(e) ⇒ Boolean
True if e is an AWS system error, i.e. something that is for sure not the caller’s fault. Used to force logging.
614 615 616 |
# File 'lib/awsbase/right_awsbase.rb', line 614 def self.system_error?(e) !e.is_a?(self) || e. =~ /InternalError|InsufficientInstanceCapacity|Unavailable/ end |
Instance Method Details
#include?(pattern) ⇒ Boolean
Does any of the error messages include the regexp pattern
? Used to determine whether to retry request.
578 579 580 581 582 583 584 585 |
# File 'lib/awsbase/right_awsbase.rb', line 578 def include?(pattern) if @errors.is_a?(Array) @errors.each{ |code, msg| return true if code =~ pattern } else return true if @errors_str =~ pattern end false end |