Commits

David Larlet  committed a822235

S3: raise IOErrors if the returned status code is not expected, thanks Sebastian Serrano

  • Participants
  • Parent commits 5878ed0

Comments (0)

Files changed (1)

File backends/S3Storage.py

         content_type = guess_type(name)[0] or "application/x-octet-stream"
         self.headers.update({'x-amz-acl': self.acl, 'Content-Type': content_type})
         response = self.connection.put(self.bucket, name, content, self.headers)
+        if response.http_response.status != 200:
+            raise IOError("S3StorageError: %s" % response.message)
 
     def _open(self, name, mode='rb'):
         remote_file = S3StorageFile(name, self, mode=mode)
         else:
             headers = {'Range': 'bytes=%s-%s' % (start_range, end_range)}
         response = self.connection.get(self.bucket, name, headers)
+        if response.http_response.status != 200:
+            raise IOError("S3StorageError: %s" % response.message)
         headers = response.http_response.msg
         return response.object.data, headers.get('etag', None), headers.get('content-range', None)
         
         return name
     
     def delete(self, name):
-        self.connection.delete(self.bucket, name)
+        response = self.connection.delete(self.bucket, name)
+        if response.http_response.status != 204:
+            raise IOError("S3StorageError: %s" % response.message)
 
     def exists(self, name):
         response = self.connection._make_request('HEAD', self.bucket, name)