Skip to content

Commit

Permalink
consolidate error slurp/reraising a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Jun 12, 2010
1 parent 6171201 commit 61e7ec0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
9 changes: 3 additions & 6 deletions lib/fog/aws/ec2.rb
Expand Up @@ -227,15 +227,12 @@ def request(params)
})
rescue Excon::Errors::Error => error
if match = error.message.match(/<Code>(.*)<\/Code><Message>(.*)<\/Message>/)
new_error = case match[1].split('.').last
raise case match[1].split('.').last
when 'NotFound'
Fog::AWS::EC2::NotFound.new(match[2])
Fog::AWS::EC2::NotFound.slurp(error, match[2])
else
Fog::AWS::EC2::Error.new("#{match[1]} => #{match[2]}")
Fog::AWS::EC2::Error.slurp(error, "#{match[1]} => #{match[2]}")
end
new_error.set_backtrace(error.backtrace)
new_error.verbose = error.message
raise new_error
else
raise error
end
Expand Down
5 changes: 1 addition & 4 deletions lib/fog/bluebox.rb
Expand Up @@ -84,10 +84,7 @@ def request(params)
rescue Excon::Errors::Error => error
raise case error
when Excon::Errors::NotFound
new_error = Fog::Bluebox::NotFound
new_error.set_backtrace(error.backtrace)
new_error.verbose = error.message
new_error
Fog::Bluebox::NotFound.slurp(error)
else
error
end
Expand Down
7 changes: 7 additions & 0 deletions lib/fog/errors.rb
Expand Up @@ -3,6 +3,13 @@ module Errors

class Error < StandardError
attr_accessor :verbose

def self.slurp(error, message = nil)
new_error = new(message)
new_error.set_backtrace(error.backtrace)
new_error.verbose = error.message
new_error
end
end

class MockNotImplemented < Fog::Errors::Error; end
Expand Down
5 changes: 1 addition & 4 deletions lib/fog/rackspace/servers.rb
Expand Up @@ -105,10 +105,7 @@ def request(params)
rescue Excon::Errors::Error => error
raise case error
when Excon::Errors::NotFound
new_error = Fog::Rackspace::Servers::NotFound
new_error.set_backtrace(error.backtrace)
new_error.verbose = error.message
new_error
Fog::Rackspace::Servers::NotFound.slurp(error)
else
error
end
Expand Down
5 changes: 1 addition & 4 deletions lib/fog/slicehost.rb
Expand Up @@ -88,10 +88,7 @@ def request(params)
rescue Excon::Errors::Error => error
raise case error
when Excon::Errors::NotFound
new_error = Fog::Slicehost::NotFound.new
new_error.set_backtrace(error.backtrace)
new_error.verbose = error.message
new_error
Fog::Slicehost::NotFound.slurp(error)
else
error
end
Expand Down

0 comments on commit 61e7ec0

Please sign in to comment.