def dlkerrors(path): """ Translate Datalake errors to FSErrors. FS errors: https://docs.pyfilesystem.org/en/latest/reference/errors.html DLK errors: https://docs.pyfilesystem.org/en/latest/reference/errors.html """ try: yield except client_error.FileNotFoundError as error: raise errors.ResourceNotFound(path, exc=error) except client_error.FileExistsError as error: raise errors.FileExists(path, exc=error) except client_error.PermissionError as error: raise errors.PermissionDenied(path, exc=error) except client_error.DatalakeBadOffsetException as error: raise errors.RemoteConnectionError(path, exc=error, msg="DatalakeBadOffsetException") except client_error.DatalakeIncompleteTransferException as error: raise errors.RemoteConnectionError( path, exc=error, msg="DatalakeIncompleteTransferException") except client_error.DatalakeRESTException as error: raise errors.RemoteConnectionError(path, exc=error, msg="DatalakeRESTException")
def s3errors(path): """Translate S3 errors to FSErrors.""" try: yield except ClientError as error: _error = error.response.get('Error', {}) error_code = _error.get('Code', None) response_meta = error.response.get('ResponseMetadata', {}) http_status = response_meta.get('HTTPStatusCode', 200) error_msg = _error.get('Message', None) if error_code == 'NoSuchBucket': raise errors.ResourceError(path, exc=error, msg=error_msg) if http_status == 404: raise errors.ResourceNotFound(path) elif http_status == 403: raise errors.PermissionDenied(path=path, msg=error_msg) else: raise errors.OperationFailed(path=path, exc=error) except SSLError as error: raise errors.OperationFailed(path, exc=error) except EndpointConnectionError as error: raise errors.RemoteConnectionError( path, exc=error, msg="{}".format(error) )
def _urlopen(self, req): try: return urlopen(req) except Exception, e: if not getattr(e, 'getcode', None): raise errors.RemoteConnectionError(str(e)) code = e.getcode() if code == 500: # Probably out of space or unhappiness error raise errors.StorageSpaceError(e.fp.read()) elif code in (400, 404, 410): # Standard not found raise errors.ResourceNotFoundError(e.fp.read()) raise errors.ResourceInvalidError(e.fp.read())
def _urlopen(self, req): self.log.debug("_urlopen %s: %s" % (repr(req), repr(req.get_full_url()))) try: return urllib2.urlopen(req) except Exception, e: if not getattr(e, 'getcode', None): raise errors.RemoteConnectionError(str(e)) code = e.getcode() if code == 500: raise errors.StorageSpaceError(e.fp.read()) elif code in (400, 404, 410): raise errors.ResourceNotFoundError(e.fp.read()) raise errors.ResourceInvalidError(e.fp.read())