Class: Fog::Ecloud::Errors::ServiceError
- Inherits:
-
Fog::Errors::Error
- Object
- Fog::Errors::Error
- Fog::Ecloud::Errors::ServiceError
- Defined in:
- lib/fog/compute/ecloud/errors.rb
Overview
The parent class for all errors in the Fog::Compute::Ecloud module.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#minor_error_code ⇒ Object
readonly
Returns the value of attribute minor_error_code.
-
#response_data ⇒ Object
readonly
Returns the value of attribute response_data.
-
#status_code ⇒ Integer
readonly
The HTTP status code returned.
Class Method Summary collapse
-
.extract_message(data) ⇒ String
Parse the response body for an error message.
-
.extract_minor_code(data) ⇒ String
Parse the response body for the minor error code.
-
.slurp(error) ⇒ Object
Parse the response from the HTTP request to create a user friendly message, including HTTP response code and error message (if any).
Instance Method Summary collapse
-
#to_s ⇒ String
Make the HTTP status code pretty.
Instance Attribute Details
#minor_error_code ⇒ Object (readonly)
Returns the value of attribute minor_error_code.
12 13 14 |
# File 'lib/fog/compute/ecloud/errors.rb', line 12 def minor_error_code @minor_error_code end |
#response_data ⇒ Object (readonly)
Returns the value of attribute response_data.
|
# File 'lib/fog/compute/ecloud/errors.rb', line 7
|
#status_code ⇒ Integer (readonly)
Returns the HTTP status code returned.
12 |
# File 'lib/fog/compute/ecloud/errors.rb', line 12 attr_reader :response_data, :status_code, :minor_error_code |
Class Method Details
.extract_message(data) ⇒ String
Parse the response body for an error message
69 70 71 72 73 74 |
# File 'lib/fog/compute/ecloud/errors.rb', line 69 def self.(data) if data.is_a?(Hash) = data[:message] end || data.inspect end |
.extract_minor_code(data) ⇒ String
Parse the response body for the minor error code
81 82 83 84 85 86 87 |
# File 'lib/fog/compute/ecloud/errors.rb', line 81 def self.extract_minor_code(data) minor_code = nil if data.is_a?(Hash) minor_code = data[:minorErrorCode] end minor_code end |
.slurp(error) ⇒ Object
Parse the response from the HTTP request to create a user friendly
message, including HTTP response code and error message (if any)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/compute/ecloud/errors.rb', line 29 def self.slurp(error) data = nil = nil status_code = nil minor_code = nil if error.response status_code = error.response.status unless error.response.body.empty? begin document = Fog::ToHashDocument.new parser = Nokogiri::XML::SAX::PushParser.new(document) parser << error.response.body parser.finish data = document.body = (data) minor_code = extract_minor_code(data) rescue => e Fog::Logger.warning("Received exception '#{e}' while decoding: #{error.response.body}") = error.response.body data = error.response.body end end end new_error = super(error, ) new_error.instance_variable_set(:@response_data, data) new_error.instance_variable_set(:@status_code, status_code) new_error.instance_variable_set(:@minor_error_code, minor_code) new_error end |
Instance Method Details
#to_s ⇒ String
Make the HTTP status code pretty
17 18 19 20 21 |
# File 'lib/fog/compute/ecloud/errors.rb', line 17 def to_s status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>" minor_code = minor_error_code ? minor_error_code : "Unknown" "[#{status} - #{minor_code}] #{super}" end |