From c87f00392a6882f74d85aa2037ebd67ff2c0d31f Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Fri, 19 Oct 2012 01:29:22 -0400 Subject: [PATCH] Add a new exception class and handled exceptions in exception messages. --- lib/fog/hp.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/fog/hp.rb b/lib/fog/hp.rb index d4c8df904..36584b64f 100644 --- a/lib/fog/hp.rb +++ b/lib/fog/hp.rb @@ -20,8 +20,13 @@ module Fog data = nil message = nil else - data = MultiJson.decode(error.response.body) - message = data['message'] + begin + data = MultiJson.decode(error.response.body) + message = data['message'] + rescue MultiJson::DecodeError + data = error.response.body #### the body is not in JSON format so just return it as it is + message = data + end end new_error = super(error, message) @@ -33,6 +38,7 @@ module Fog class InternalServerError < ServiceError; end class Conflict < ServiceError; end class NotFound < ServiceError; end + class Forbidden < ServiceError; end class ServiceUnavailable < ServiceError; end class BadRequest < ServiceError