mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] fix JSON error parsing
Prevent an error in extracting the error message from the JSON response from discarding the successfully parsed JSON response body. For example, the parsed error response body from a failed PUT request to store a SLO manifest object would be: { 'Errors' => [['path', 'error'], ['path', 'error']] }
This commit is contained in:
parent
e6ce26742f
commit
d713739d97
1 changed files with 11 additions and 1 deletions
|
@ -28,7 +28,7 @@ module Fog
|
|||
unless error.response.body.empty?
|
||||
begin
|
||||
data = Fog::JSON.decode(error.response.body)
|
||||
message = data.values.first ? data.values.first['message'] : data['message']
|
||||
message = extract_message(data)
|
||||
rescue => e
|
||||
Fog::Logger.warning("Received exception '#{e}' while decoding>> #{error.response.body}")
|
||||
message = error.response.body
|
||||
|
@ -42,6 +42,16 @@ module Fog
|
|||
new_error.instance_variable_set(:@status_code, status_code)
|
||||
new_error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.extract_message(data)
|
||||
if data.is_a?(Hash)
|
||||
message = data.values.first['message'] if data.values.first.is_a?(Hash)
|
||||
message ||= data['message']
|
||||
end
|
||||
message || data.inspect
|
||||
end
|
||||
end
|
||||
|
||||
class InternalServerError < ServiceError; end
|
||||
|
|
Loading…
Reference in a new issue