From 8f6c8770ab7bed47c7c6b2ce541ba3ecf10de6d2 Mon Sep 17 00:00:00 2001 From: Daniel Lobato Date: Fri, 10 Oct 2014 10:43:17 +0200 Subject: [PATCH] Raise docker-api errors up --- lib/fog/fogdocker/core.rb | 8 +------- lib/fog/fogdocker/errors.rb | 9 +++++++++ lib/fog/fogdocker/requests/compute/container_action.rb | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 lib/fog/fogdocker/errors.rb diff --git a/lib/fog/fogdocker/core.rb b/lib/fog/fogdocker/core.rb index 2594306ef..e438f688d 100644 --- a/lib/fog/fogdocker/core.rb +++ b/lib/fog/fogdocker/core.rb @@ -1,15 +1,9 @@ require 'fog/core' +require 'fog/fogdocker/errors' module Fog module Fogdocker extend Fog::Provider - - module Errors - class ServiceError < Fog::Errors::Error; end - class SecurityError < ServiceError; end - class NotFound < ServiceError; end - end - service(:compute, 'Compute') end end diff --git a/lib/fog/fogdocker/errors.rb b/lib/fog/fogdocker/errors.rb new file mode 100644 index 000000000..9238990aa --- /dev/null +++ b/lib/fog/fogdocker/errors.rb @@ -0,0 +1,9 @@ +module Fog + module Errors + module Fogdocker + class ServiceError < Fog::Errors::Error; end + class AuthenticationError < ServiceError; end + end + end +end + diff --git a/lib/fog/fogdocker/requests/compute/container_action.rb b/lib/fog/fogdocker/requests/compute/container_action.rb index c4d8c1561..9b75f678a 100644 --- a/lib/fog/fogdocker/requests/compute/container_action.rb +++ b/lib/fog/fogdocker/requests/compute/container_action.rb @@ -7,6 +7,14 @@ module Fog raise ArgumentError, "action is a required parameter" unless options.key? :action container = Docker::Container.get(options[:id]) 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