Sha256: c5afa32ff95863d37ae4c8a1fed382d27b6df60ba8a9dd2bf0a69e0685466351

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

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

module FakeServiceBus
  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(/^FakeServiceBus::/, '')
      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

1 entries across 1 versions & 1 rubygems

Version Path
fake_servicebus-0.0.2 lib/fake_servicebus/error_response.rb