[ec2] extract NotFound errors and react properly to them in models

This commit is contained in:
geemus 2010-05-26 17:27:17 -07:00
parent 7033686193
commit 2c0aa3b1b2
9 changed files with 20 additions and 11 deletions

View File

@ -26,7 +26,10 @@ require 'fog/parser'
require 'fog/ssh'
module Fog
class Error < StandardError; end
module Errors
class Error < StandardError; end
class NotFound < Fog::Errors::Error; end
end
end
require 'fog/aws'
@ -38,7 +41,7 @@ require 'fog/vcloud'
module Fog
class MockNotImplemented < Fog::Error; end
class MockNotImplemented < Fog::Errors::Error; end
unless const_defined?(:VERSION)
VERSION = '0.1.3'

View File

@ -2,7 +2,8 @@ module Fog
module AWS
module EC2
class Error < Fog::Error; end
class Error < Fog::Errors::Error; end
class NotFound < Fog::Errors::NotFound; end
def self.new(options={})
@ -226,7 +227,12 @@ module Fog
})
rescue Excon::Errors::Error => error
if match = error.message.match(/<Code>(.*)<\/Code><Message>(.*)<\/Message>/)
new_error = Fog::AWS::EC2::Error.new("#{match[1]} => #{match[2]}")
new_error = case match[1].split('.').last
when 'NotFound'
Fog::AWS::EC2::NotFound.new(match[2])
else
Fog::AWS::EC2::Error.new("#{match[1]} => #{match[2]}")
end
new_error.set_backtrace(error.backtrace)
raise new_error
else

View File

@ -51,7 +51,7 @@ module Fog
if public_ip
all(public_ip).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end

View File

@ -38,7 +38,7 @@ module Fog
if image_id
all(image_id).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end
end

View File

@ -38,7 +38,7 @@ module Fog
if key_name
all(key_name).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end

View File

@ -38,7 +38,7 @@ module Fog
if group_name
all(group_name).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end

View File

@ -44,7 +44,7 @@ module Fog
if server_id
all(server_id).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end

View File

@ -54,7 +54,7 @@ module Fog
if snapshot_id
all(snapshot_id).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end

View File

@ -47,7 +47,7 @@ module Fog
if volume_id
all(volume_id).first
end
rescue Excon::Errors::BadRequest
rescue Fog::Errors::NotFound
nil
end