Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[LIB-175] add special error if user is not found;
  • Loading branch information
opalczynski committed Jun 7, 2016
commit c3029a1a538f6c3c017da4243e6aff65839c5f06
4 changes: 4 additions & 0 deletions syncano/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ class SyncanoDoesNotExist(SyncanoException):

class RevisionMismatchException(SyncanoRequestError):
"""Revision do not match with expected one"""


class UserNotFound(SyncanoRequestError):
"""Special error to handle user not found case."""
11 changes: 9 additions & 2 deletions syncano/models/accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from syncano.exceptions import SyncanoValueError
from syncano.exceptions import SyncanoValueError, SyncanoRequestError, UserNotFound

from . import fields
from .base import Model
Expand Down Expand Up @@ -214,7 +214,14 @@ def _group_users_method(self, user_id=None, method='GET'):
if user_id is not None:
endpoint += '{}/'.format(user_id)
connection = self._get_connection()
return connection.request(method, endpoint)
try:
response = connection.request(method, endpoint)
except SyncanoRequestError as e:
if e.status_code == 404:
raise UserNotFound(e.status_code, 'User not found.')
raise

return response

def list_users(self):
return self._group_users_method()
Expand Down