Skip to content

Commit a3c0059

Browse files
Test for raising error
1 parent 7fc87a9 commit a3c0059

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

inventree/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ def list(cls, api, **kwargs):
237237
except requests.exceptions.HTTPError as e:
238238
logger.error(f"Error during list request: {e}")
239239
# Return an empty list
240-
return []
240+
241+
raise_error = kwargs.get('raise_error', False)
242+
243+
if raise_error:
244+
raise e
245+
else:
246+
return []
241247

242248
if response is None:
243249
return []

test/test_order.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ def test_invalid_list(self):
401401
results = order.PurchaseOrder.list(self.api, project_code=999999999)
402402
self.assertEqual(len(results), 0)
403403

404+
# Try the same again, but raise the eror
405+
with self.assertRaises(HTTPError):
406+
results = order.PurchaseOrder.list(
407+
self.api,
408+
project_code=999999999,
409+
raise_error=True
410+
)
411+
404412
# Find a valid project code
405413
n = ProjectCode.count(self.api)
406414

0 commit comments

Comments
 (0)