Sha256: 0432c385fd37379859c7dcdd289499516fd896e2681993fbca8e98f9dd166a70

Contents?: true

Size: 1.71 KB

Versions: 112

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Aws
  module S3
    module Plugins

      # A handful of Amazon S3 operations will respond with a 200 status
      # code but will send an error in the response body. This plugin
      # injects a handler that will parse 200 response bodies for potential
      # errors, allowing them to be retried.
      # @api private
      class Http200Errors < Seahorse::Client::Plugin

        class Handler < Seahorse::Client::Handler

          def call(context)
            @handler.call(context).on(200) do |response|
              if error = check_for_error(context)
                context.http_response.status_code = 500
                response.data = nil
                response.error = error
              end
            end
          end

          def check_for_error(context)
            xml = context.http_response.body_contents
            if xml.match(/<Error>/)
              error_code = xml.match(/<Code>(.+?)<\/Code>/)[1]
              error_message = xml.match(/<Message>(.+?)<\/Message>/)[1]
              S3::Errors.error_class(error_code).new(context, error_message)
            elsif !xml.match(/<\w/) # Must have the start of an XML Tag
              # Other incomplete xml bodies will result in XML ParsingError
              Seahorse::Client::NetworkingError.new(
                S3::Errors
                  .error_class('InternalError')
                  .new(context, 'Empty or incomplete response body')
              )
            end
          end
        end

        handler(
          Handler,
          step: :sign,
          operations: [
            :complete_multipart_upload,
            :copy_object,
            :upload_part_copy,
          ]
        )
      end
    end
  end
end

Version data entries

112 entries across 112 versions & 1 rubygems

Version Path
aws-sdk-s3-1.134.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.133.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.132.1 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.132.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.131.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.130.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.129.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.128.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.127.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.126.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.125.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.124.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.123.2 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.123.1 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.123.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.122.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.121.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.120.1 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.120.0 lib/aws-sdk-s3/plugins/http_200_errors.rb
aws-sdk-s3-1.119.2 lib/aws-sdk-s3/plugins/http_200_errors.rb