mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Add additional cases in Fog::AWS::Errors.match_error helper
This commit is contained in:
parent
e33f11c915
commit
010883c1bf
1 changed files with 26 additions and 5 deletions
|
@ -2,11 +2,32 @@ module Fog
|
|||
module AWS
|
||||
module Errors
|
||||
def self.match_error(error)
|
||||
matcher = lambda {|s| s.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)}
|
||||
[error.message, error.response.body].each(&Proc.new {|s|
|
||||
match = matcher.call(s)
|
||||
return {:code => match[1].split('.').last, :message => match[2]} if match
|
||||
})
|
||||
if !Fog::AWS.json_response?(error.response)
|
||||
matchers = [
|
||||
lambda {|s| s.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)},
|
||||
lambda {|s| s.match(/.*<(.+Exception)>(?:.*<Message>(.*)<\/Message>)/m)}
|
||||
]
|
||||
[error.message, error.response.body].each(&Proc.new {|s|
|
||||
matchers.each do |matcher|
|
||||
match = matcher.call(s)
|
||||
return {:code => match[1].split('.').last, :message => match[2]} if match
|
||||
end
|
||||
})
|
||||
else
|
||||
begin
|
||||
full_msg_error = Fog::JSON.decode(error.response.body)
|
||||
if (full_msg_error.has_key?('Message') || full_msg_error.has_key?('message')) &&
|
||||
error.response.headers.has_key?('x-amzn-ErrorType')
|
||||
matched_error = {
|
||||
:code => error.response.headers['x-amzn-ErrorType'].split(':').first,
|
||||
:message => full_msg_error['Message'] || full_msg_error['message']
|
||||
}
|
||||
return matched_error
|
||||
end
|
||||
rescue Fog::JSON::DecodeError => e
|
||||
Fog::Logger.warning("Error parsing response json - #{e}")
|
||||
end
|
||||
end
|
||||
{} # we did not match the message or response body
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue