Sha256: ec7488e4af65cc0fb1ce7c158f5924cd533a5a7a94f7c52e4d82b18f4399d14a

Contents?: true

Size: 913 Bytes

Versions: 3

Compression:

Stored size: 913 Bytes

Contents

require 'yaml'
require 'builder'
require 'securerandom'

module FakeSQS
  class ErrorResponse

    attr_reader :error

    def initialize(error)
      @error = error
    end

    def status
      @status ||= statuses.fetch(code)
    end

    def body
      xml = Builder::XmlMarkup.new()
      xml.ErrorResponse do
        xml.Error do
          xml.Type type
          xml.Code code
          xml.Message error.to_s
          xml.Detail
        end
        xml.RequestId SecureRandom.uuid
      end
    end

    private

    def code
      code = error.class.name.sub(/^FakeSQS::/, '')
      if statuses.has_key?(code)
        code
      else
        "InternalError"
      end
    end

    def type
      if status < 500
        "Sender"
      else
        "Receiver"
      end
    end

    def statuses
      @statuses ||= YAML.load_file(File.expand_path('../error_responses.yml', __FILE__))
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fake_sqs-0.4.3 lib/fake_sqs/error_response.rb
fake_sqs-0.4.2 lib/fake_sqs/error_response.rb
fake_sqs-0.4.1 lib/fake_sqs/error_response.rb