File: errors.rb

package info (click to toggle)
ruby-aws-sdk-s3 1.170.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,740 kB
  • sloc: ruby: 16,388; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 1,547 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module Aws
  module S3
    module Errors
      # Hijack PermanentRedirect dynamic error to include the bucket, region,
      # and endpoint.
      class PermanentRedirect < ServiceError
        # @param [Seahorse::Client::RequestContext] context
        # @param [String] message
        # @param [Aws::S3::Types::PermanentRedirect] _data
        def initialize(context, message, _data = Aws::EmptyStructure.new)
          data = Aws::S3::Types::PermanentRedirect.new(message: message)
          body = context.http_response.body_contents
          if (endpoint = body.match(/<Endpoint>(.+?)<\/Endpoint>/))
            data.endpoint = endpoint[1]
          end
          if (bucket = body.match(/<Bucket>(.+?)<\/Bucket>/))
            data.bucket = bucket[1]
          end
          data.region = context.http_response.headers['x-amz-bucket-region']
          super(context, message, data)
        end
      end

      # Hijack PermanentRedirect (HeadBucket case - no body) dynamic error to
      # include the region.
      class Http301Error < ServiceError
        # @param [Seahorse::Client::RequestContext] context
        # @param [String] message
        # @param [Aws::S3::Types::PermanentRedirect] _data
        def initialize(context, message, _data = Aws::EmptyStructure.new)
          data = Aws::S3::Types::PermanentRedirect.new(message: message)
          data.region = context.http_response.headers['x-amz-bucket-region']
          super(context, message, data)
        end
      end
    end
  end
end