Sha256: 5c634371093d09178f0597e49501b33df1c530b55bb00132ca5d1af591ba4d16

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

module Aws
  module Json
    class ErrorHandler < Xml::ErrorHandler

      # @param [Seahorse::Client::RequestContext] context
      # @return [Seahorse::Client::Response]
      def call(context)
        @handler.call(context).on(300..599) do |response|
          response.error = error(context)
          response.data = nil
        end
      end

      private

      def extract_error(body, context)
        json = MultiJson.load(body)
        code = error_code(json, context)
        message = error_message(code, json)
        [code, message]
      rescue MultiJson::ParseError
        [http_status_error_code(context), '']
      end

      def error_code(json, context)
        code = json['__type']
        code ||= json['code']
        code ||= context.http_response.headers['x-amzn-errortype']
        if code
          code.split('#').last
        else
          http_status_error_code(context)
        end
      end

      def error_message(code, json)
        if code == 'RequestEntityTooLarge'
          'Request body must be less than 1 MB'
        else
          json['message'] || json['Message'] || ''
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.48 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.47 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.46 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.45 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.44 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.43 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.42 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.41 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.40 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.39 lib/aws-sdk-core/json/error_handler.rb
aws-sdk-core-2.0.38 lib/aws-sdk-core/json/error_handler.rb