mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add an Errors module for handling HP provider specific exceptions.
This commit is contained in:
parent
44afa4172e
commit
f781680309
1 changed files with 37 additions and 0 deletions
|
@ -4,6 +4,43 @@ module Fog
|
|||
module HP
|
||||
extend Fog::Provider
|
||||
|
||||
module Errors
|
||||
class ServiceError < Fog::Errors::Error
|
||||
attr_reader :response_data
|
||||
|
||||
def self.slurp(error)
|
||||
if error.response.body.empty?
|
||||
data = nil
|
||||
message = nil
|
||||
else
|
||||
data = MultiJson.decode(error.response.body)
|
||||
message = data['message']
|
||||
end
|
||||
|
||||
new_error = super(error, message)
|
||||
new_error.instance_variable_set(:@response_data, data)
|
||||
new_error
|
||||
end
|
||||
end
|
||||
|
||||
class InternalServerError < ServiceError; end
|
||||
class Conflict < ServiceError; end
|
||||
class NotFound < ServiceError; end
|
||||
class ServiceUnavailable < ServiceError; end
|
||||
|
||||
class BadRequest < ServiceError
|
||||
attr_reader :validation_errors
|
||||
|
||||
def self.slurp(error)
|
||||
new_error = super(error)
|
||||
unless new_error.response_data.nil?
|
||||
new_error.instance_variable_set(:@validation_errors, new_error.response_data['validationErrors'])
|
||||
end
|
||||
new_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
service(:cdn, 'hp/cdn', 'CDN')
|
||||
service(:compute, 'hp/compute', 'Compute')
|
||||
service(:storage, 'hp/storage', 'Storage')
|
||||
|
|
Loading…
Add table
Reference in a new issue