Class: CloudDB::Exception
- Inherits:
-
Object
- Object
- CloudDB::Exception
- Defined in:
- lib/clouddb/exception.rb
Defined Under Namespace
Classes: Authentication, BadRequest, CloudDBError, Connection, ExpiredAuthToken, ImmutableEntity, InstanceFault, ItemNotFound, MissingArgument, Other, OverLimit, ServiceFault, ServiceUnavailable, Syntax, Unauthorized, UnprocessableEntity
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 CloudDB::Exception namespace.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/clouddb/exception.rb', line 55 def self.raise_exception(response) return if response.code =~ /^20.$/ begin fault = nil info = nil 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) rescue NameError, JSON::ParserError raise CloudDB::Exception::Other.new("The server returned status #{response.code} with body #{response.body}", response.code, response.body) end end |