Raise docker-api errors up

This commit is contained in:
Daniel Lobato 2014-10-10 10:43:17 +02:00
parent b18ffc9776
commit 8f6c8770ab
3 changed files with 18 additions and 7 deletions

View File

@ -1,15 +1,9 @@
require 'fog/core' require 'fog/core'
require 'fog/fogdocker/errors'
module Fog module Fog
module Fogdocker module Fogdocker
extend Fog::Provider extend Fog::Provider
module Errors
class ServiceError < Fog::Errors::Error; end
class SecurityError < ServiceError; end
class NotFound < ServiceError; end
end
service(:compute, 'Compute') service(:compute, 'Compute')
end end
end end

View File

@ -0,0 +1,9 @@
module Fog
module Errors
module Fogdocker
class ServiceError < Fog::Errors::Error; end
class AuthenticationError < ServiceError; end
end
end
end

View File

@ -7,6 +7,14 @@ module Fog
raise ArgumentError, "action is a required parameter" unless options.key? :action raise ArgumentError, "action is a required parameter" unless options.key? :action
container = Docker::Container.get(options[:id]) container = Docker::Container.get(options[:id])
downcase_hash_keys container.send(options[:action]).json downcase_hash_keys container.send(options[:action]).json
rescue Docker::Error::NotFoundError => e
raise Fog::Errors::Error::NotFound.new(e.message)
rescue Docker::Error::TimeoutError => e
raise Fog::Errors::Error::TimeoutError.new(e.message)
rescue Docker::Error::UnauthorizedError => e
raise Fog::Errors::Fogdocker::ServiceError::AuthenticationError.new(e.message)
rescue Docker::Error::DockerError => e
raise Fog::Errors::Fogdocker::ServiceError.new(e.message)
end end
end end