Sha256: da22302186d735c61703b925f073fb95e355d4c29da2ed3ceb0a2080f89f2fb7

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 KB

Contents

# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

module AWS
  class DynamoDB

    module Errors

      module ModeledError

        def initialize(request = nil, response = nil)
          message = extract_message(response)
          include_error_type(response) if response
          super(request, response, message)
        end

        def extract_message(response)
          if response and response.body != ''
            JSON.load(response.body)["message"] || code
          elsif code == 'RequestEntityTooLarge'
            'Request body must be less than 1 MB'
          else
            code
          end
        end

        def include_error_type(response)
          if response.status >= 500
            extend Errors::ServerError
          else
            extend Errors::ClientError
          end
        end

        def code
          self.class.name =~ /(::)?([^:]+)$/
          $2
        end

      end

      include Core::LazyErrorClasses

    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
aws-sdk-1.4.1 lib/aws/dynamo_db/errors.rb
aws-sdk-1.4.0 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.9 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.8 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.7 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.6 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.5 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.4 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.3 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.2 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.1 lib/aws/dynamo_db/errors.rb
aws-sdk-1.3.0 lib/aws/dynamo_db/errors.rb