Skip to content

Commit b453be3

Browse files
committed
using ServiceType, fixing some stuff
1 parent ca3cd91 commit b453be3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/superannotate/lib/core/service_types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ def __init__(self, response, content_type=None):
7979
"reason": response.reason,
8080
"content": response.content,
8181
}
82-
if response.ok:
83-
if content_type and not content_type is not self.__class__:
82+
try:
83+
if content_type and content_type is not self.__class__:
8484
data["data"] = content_type(**response.json())
8585
else:
8686
data["data"] = response.json()
87+
except Exception as e:
88+
data["data"] = {}
8789
super().__init__(**data)
8890

8991
@property
@@ -93,4 +95,7 @@ def ok(self):
9395
@property
9496
def error(self):
9597
default_message = self.reason if self.reason else "Unknown Error"
96-
return getattr(self.data, "error", default_message)
98+
if isinstance(self.data, dict):
99+
return self.data.get("error", default_message)
100+
else:
101+
return getattr(self.data, "error", default_message)

src/superannotate/lib/core/usecases/items.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def validate_item_names(
216216

217217
def execute(self):
218218
cnt_assigned = 0
219+
total_count = len(self._item_names)
219220
if self.is_valid():
220221
for i in range(0, len(self._item_names), self.CHUNK_SIZE):
221222
response = self._service.assign_items(
@@ -225,15 +226,16 @@ def execute(self):
225226
user=self._user,
226227
item_names=self._item_names[i : i + self.CHUNK_SIZE], # noqa: E203
227228
)
228-
if not response.ok and "error" in response: # User not found
229+
if not response.ok and response.error: # User not found
230+
print(response.error)
229231
self._response.errors += response.error
230-
break
232+
return self._response
231233

232234
cnt_assigned += response.data["successCount"]
233235
logger.info(
234-
f"Assigned {cnt_assigned}/{len(self._item_names)} items to user {self._user}"
236+
f"Assigned {cnt_assigned}/{total_count} items to user {self._user}"
235237
)
236-
return self._response, cnt_assigned
238+
return self._response
237239

238240

239241
class UnAssignItemsUseCase(BaseUseCase):

0 commit comments

Comments
 (0)