Module: Deltacloud::EC2::Errors

Defined in:
lib/ec2/helpers/errors.rb

Instance Method Summary collapse

Instance Method Details

#error_for_code(code) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ec2/helpers/errors.rb', line 37

def error_for_code(code)
  case code
    when 401 then 'AuthFailure'
    when 500 then 'InternalError'
    else "Unavailable (#{code})"
  end
end

#report_error(code) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ec2/helpers/errors.rb', line 19

def report_error(code)
  error = (request.env['sinatra.error'] || @exception)
  code = 500 if not code and not error.class.method_defined? :code
  Nokogiri::XML::Builder.new do |xml|
    xml.send(:Response) {
      xml.send(:Errors) {
        xml.send(:Code, error_for_code(code))
        xml.send(:Message, error.respond_to?(:message) ? error.message : '')
      }
      xml.send(:RequestID, request_id)
    }
  end.to_xml
end

#request_idObject



33
34
35
# File 'lib/ec2/helpers/errors.rb', line 33

def request_id
  Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{request.env['HTTP_USER_AGENT']}#{Time.now.to_i}#{rand(250)}")
end