Added better handling for errors.

This commit is contained in:
Bob Aman 2011-09-22 12:21:05 +03:00
parent 4fa30fc051
commit a9ae33bb47
1 changed files with 5 additions and 2 deletions

View File

@ -594,10 +594,13 @@ module Google
def execute!(*params) def execute!(*params)
result = self.execute(*params) result = self.execute(*params)
status, _, _ = result.response status, _, _ = result.response
if result.data.respond_to?(:error) if result.data.respond_to?(:error) &&
result.data.error.respond_to?(:message)
# You're going to get a terrible error message if the response isn't # You're going to get a terrible error message if the response isn't
# parsed successfully as an error. # parsed successfully as an error.
error_message = result.data.error error_message = result.data.error.message
elsif result.data['error'] && result.data['error']['message']
error_message = result.data['error']['message']
end end
if status >= 400 && status < 500 if status >= 400 && status < 500
raise ClientError, raise ClientError,