Class: RightScale::CloudApi::Parser::AWS::S3::ResponseError

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/aws/s3/parsers/response_error.rb

Overview

S3 response error

Class Method Summary collapse

Class Method Details

.parse(response, options = {}) ⇒ String

Parses HTTP error message from a response body

Examples:

{"Error"=>
    {"Message"=>"The specified key does not exist.",
    "RequestId"=>"B9BE7751749FA764",
    "Code"=>"NoSuchKey",
    "HostId"=>
      "xtvFjUBrzKb6ndg3XTlGdAkGPm8KByqCzcLdK83fHi++ztDOC83Bv3+uH82DIBHj",
    "Key"=>"boot.jpg-"}}

Parameters:

  • response (RightScale::CloudApi::HttpResponse)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :xml_parser (Object)

Returns:

  • (String)

    to be displayed/logged.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cloud/aws/s3/parsers/response_error.rb', line 52

def self.parse(response, options={})
  body   = response.body.to_s
  result = "#{response.code}"

  return result if body._blank?

  is_xml = response['content-type'].to_s[/xml/] ||
    body[/\A<\?xml /]

  if is_xml
    hash  = Utils::get_xml_parser_class(options[:xml_parser]).parse(body)
    error = hash["Error"]
    result << (error ? ": #{error['Code']}: #{error['Message']} (RequestID: #{error['RequestId']})" : ": #{body}")
  else
    result << ": #{body}"
  end
  result
end