Skip to content

Commit 136db8a

Browse files
authored
raise exeption on notifications error (#256)
Co-authored-by: Saimon Michelson <saimon.michelson@gmail.com>
1 parent 2754edc commit 136db8a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cterasdk/asynchronous/core/notifications.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .base_command import BaseCommand
77
from ...common import Object
88
from ...lib import CursorResponse
9-
from ...exceptions import ClientResponseException
9+
from ...exceptions import ClientResponseException, NotificationsError
1010

1111

1212
class Notifications(BaseCommand):
@@ -26,11 +26,16 @@ async def get(self, cloudfolders=None, cursor=None, max_results=None):
2626
2727
:returns: An asynchronous iterator
2828
:rtype: cterasdk.asynchronous.core.iterator.CursorAsyncIterator
29+
:raises: cterasdk.exceptions.NotificationsError
2930
"""
3031
param = await self._create_parameter(cloudfolders, cursor)
3132
param.max_results = max_results if max_results is not None else 2000
3233
logging.getLogger('cterasdk.metadata.connector').debug('Listing updates.')
33-
return CursorResponse(await self._core.v2.api.post('/metadata/list', param))
34+
response = await self._core.v2.api.post('/metadata/list', param)
35+
if response is not None:
36+
return CursorResponse(response)
37+
logging.getLogger('cterasdk.metadata.connector').error('An error occurred while trying to retrieve notifications.')
38+
raise NotificationsError(cloudfolders, cursor)
3439

3540
async def _create_parameter(self, cloudfolders, cursor):
3641
param = Object()

cterasdk/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def __init__(self, error_object):
3030
super().__init__('An error occurred while processing the HTTP request.', error_object)
3131

3232

33+
class NotificationsError(CTERAException):
34+
35+
def __init__(self, cloudfolders, cursor):
36+
super().__init__('An error occurred while trying to retrieve notifications.', cloudfolders=cloudfolders, cursor=cursor)
37+
38+
3339
class ObjectNotFoundException(CTERAException):
3440

3541
def __init__(self, message, object_ref, **kwargs):

0 commit comments

Comments
 (0)