Repository: libcloud Updated Branches: refs/heads/trunk 341ceb11e -> 206a5b49b
Support CONFLICT response for Google Cloud's API If the status code for a call to the Google Cloud's API is 409 (CONFLICT), and the code of the error is 'alreadyExists', consider the resource as already existing and create the correct error. Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/532ce827 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/532ce827 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/532ce827 Branch: refs/heads/trunk Commit: 532ce827ce8f4d67080c0e39bfe4950f24e9f8e5 Parents: 341ceb1 Author: Franck Cuny <[email protected]> Authored: Sun Oct 19 22:44:01 2014 -0700 Committer: Tomaz Muraus <[email protected]> Committed: Thu Oct 23 16:15:28 2014 +0800 ---------------------------------------------------------------------- libcloud/common/google.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/532ce827/libcloud/common/google.py ---------------------------------------------------------------------- diff --git a/libcloud/common/google.py b/libcloud/common/google.py index b805ee1..069b8dd 100644 --- a/libcloud/common/google.py +++ b/libcloud/common/google.py @@ -201,7 +201,7 @@ class GoogleResponse(JsonResponse): code = err.get('code') message = err.get('message') else: - code = None + code = err.get('reason', None) message = body.get('error_description', err) return (code, message) @@ -226,14 +226,14 @@ class GoogleResponse(JsonResponse): body = self.body json_error = True - if self.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]: + if self.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED, httplib.CONFLICT]: if json_error: raise JsonParseError(body, self.status, None) elif 'error' in body: (code, message) = self._get_error(body) if code == 'QUOTA_EXCEEDED': raise QuotaExceededError(message, self.status, code) - elif code == 'RESOURCE_ALREADY_EXISTS': + elif (code == 'RESOURCE_ALREADY_EXISTS' or code == 'alreadyExists'): raise ResourceExistsError(message, self.status, code) elif code.startswith('RESOURCE_IN_USE'): raise ResourceInUseError(message, self.status, code)
