Class: OpenStack::Exception
- Inherits:
-
Object
- Object
- OpenStack::Exception
- Defined in:
- lib/openstack/connection.rb
Overview
OpenStack::Exception
Defined Under Namespace
Classes: Authentication, BackupOrResizeInProgress, BadMediaType, BadMethod, BadRequest, BuildInProgress, ComputeError, ComputeFault, Connection, ExpiredAuthToken, InvalidArgument, ItemNotFound, MissingArgument, NotImplemented, Other, OverLimit, PersonalityFilePathTooLong, PersonalityFileTooLarge, ResizeNotAllowed, ResourceStateConflict, ServerCapacityUnavailable, ServiceUnavailable, TooManyPersonalityItems, Unauthorized
Class Method Summary collapse
-
.raise_exception(response) ⇒ Object
In the event of a non-200 HTTP status code, this method takes the HTTP response, parses the JSON from the body to get more information about the exception, then raises the proper error.
Class Method Details
.raise_exception(response) ⇒ Object
In the event of a non-200 HTTP status code, this method takes the HTTP response, parses the JSON from the body to get more information about the exception, then raises the proper error. Note that all exceptions are scoped in the OpenStack::Compute::Exception namespace.
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/openstack/connection.rb', line 422 def self.raise_exception(response) return if response.code =~ /^20.$/ begin fault = nil info = nil if response.body.nil? && response.code == "404" #HEAD ops no body returned exception_class = self.const_get("ItemNotFound") raise exception_class.new("The resource could not be found", "404", "") else JSON.parse(response.body).each_pair do |key, val| fault=key info=val end exception_class = self.const_get(fault[0,1].capitalize+fault[1,fault.length]) raise exception_class.new(info["message"], response.code, response.body) end rescue JSON::ParserError => parse_error deal_with_faulty_error(response, parse_error) rescue NameError raise OpenStack::Exception::Other.new("The server returned status #{response.code}", response.code, response.body) end end |