Skip to content

Commit b06034a

Browse files
author
Ed Hazledine
committed
Handle error in JSON decode
1 parent 7f3ae33 commit b06034a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

typesense/documents.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22

3+
from typesense.exceptions import TypesenseClientError
4+
35
from .document import Document
46
from .logger import logger
57

@@ -62,7 +64,11 @@ def import_(self, documents, params=None):
6264

6365
response_objs = []
6466
for res_obj_str in res_obj_strs:
65-
response_objs.append(json.loads(res_obj_str))
67+
try:
68+
res_obj_json = json.loads(res_obj_str)
69+
except json.JSONDecodeError as e:
70+
raise TypesenseClientError("Invalid response") from e
71+
response_objs.append(res_obj_json)
6672

6773
return response_objs
6874
else:

0 commit comments

Comments
 (0)