Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
Detect and raise cloud storage errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed May 31, 2013
1 parent 4d5404a commit 1abab72
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/handlers/cloud_storage.py
Expand Up @@ -7,6 +7,7 @@
from cStringIO import StringIO
from base64 import b64encode
from urlparse import urlparse, parse_qs
from xml.etree import ElementTree
import cherrypy
import handlers
import json
Expand Down Expand Up @@ -194,9 +195,19 @@ def modify_object(obj,
headers = {key: value for key, value in headers.iteritems()
if value is not None}

return urlfetch.fetch("https://storage.googleapis.com/" +
urllib.quote(_object_path(obj)),
method="PUT", headers=headers)
response = urlfetch.fetch("https://storage.googleapis.com/" +
urllib.quote(_object_path(obj)),
method="PUT",
headers=headers,
follow_redirects=True)
if response.status_code == 200: return

xml = ElementTree.XML(response.content)
raise handlers.http_error(500, "Cloud storage %s error: %s\n%s" % (
response.status_code,
xml.find('Code').text,
xml.find('Message').text
))

def delete_object(obj):
"""Deletes an object from cloud storage."""
Expand Down

4 comments on commit 1abab72

@munificent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this also cause the upload to fail? Is there a test for this?

@nex3
Copy link
Contributor Author

@nex3 nex3 commented on 1abab72 Jun 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, any non-200 response will cause the upload to fail in a way that's visible to the user.

There aren't tests since we can't really test against the live cloud storage API. I've thoroughly tested this manually, though, by forcing the cloud storage copy step to fail with bad headers.

@munificent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍮

@nex3
Copy link
Contributor Author

@nex3 nex3 commented on 1abab72 Jun 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍮

cust that out

Please sign in to comment.