mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Inspect error.response.body, not error.message
Recent versions of excon have a middleware component, Excon::Middleware::Expects and fog requests mostly record an expectation of a 200 status code. Some calls to AWS return status other than 200 and in some cases the error handling obscures the underlying error. Current handling parsed error.message; this instance of error is constructed by excon and includes the response as an attribute. The message is always something like 'Expected(200) <=> Actual(404 Not Found)' and so the parsing never succeeds. Instead we now attempt to parse error.response.body which should allow extraction of the underlying AWS Code value, which in turn will produce an exception that points to the actual underlying cause.
This commit is contained in:
parent
3c03e4cba1
commit
b7b8367770
9 changed files with 12 additions and 8 deletions
|
@ -153,7 +153,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
case match[1]
|
||||
when 'AlreadyExists'
|
||||
#raise Fog::AWS::AutoScaling::IdentifierTaken.new(match[2])
|
||||
|
|
|
@ -131,7 +131,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
raise case match[1].split('.').last
|
||||
when 'InvalidParameterValue'
|
||||
Fog::AWS::ElasticBeanstalk::InvalidParameterError.slurp(error, match[2])
|
||||
|
|
|
@ -108,7 +108,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
raise case match[1].split('.').last
|
||||
when 'NotFound', 'ValidationError'
|
||||
Fog::AWS::CloudFormation::NotFound.slurp(error, match[2])
|
||||
|
|
|
@ -392,7 +392,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
raise case match[1].split('.').last
|
||||
when 'NotFound', 'Unknown'
|
||||
Fog::Compute::AWS::NotFound.slurp(error, match[2])
|
||||
|
|
|
@ -104,7 +104,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>?)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>?)/m)
|
||||
case match[1]
|
||||
when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound',
|
||||
'CacheClusterNotFound'
|
||||
|
|
|
@ -191,7 +191,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
case match[1]
|
||||
when 'CertificateNotFound'
|
||||
raise Fog::AWS::IAM::NotFound.slurp(error, match[2])
|
||||
|
|
|
@ -208,7 +208,7 @@ module Fog
|
|||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
case match[1]
|
||||
when 'CertificateNotFound', 'NoSuchEntity'
|
||||
raise Fog::AWS::IAM::NotFound.slurp(error, match[2])
|
||||
|
|
|
@ -218,6 +218,10 @@ module Fog
|
|||
raise
|
||||
end
|
||||
else
|
||||
case error.message
|
||||
when 'Not Found'
|
||||
raise Fog::AWS::RDS::NotFound.slurp(error, 'RDS Instance not found')
|
||||
end
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
|
|
@ -114,7 +114,7 @@ module Fog
|
|||
|
||||
response
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
if match = error.response.body.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
|
||||
case match[1]
|
||||
when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError'
|
||||
raise Fog::AWS::STS.const_get(match[1]).slurp(error, match[2])
|
||||
|
|
Loading…
Reference in a new issue