diff --git a/inventree/base.py b/inventree/base.py index ea247d3..4a56c48 100644 --- a/inventree/base.py +++ b/inventree/base.py @@ -237,7 +237,13 @@ def list(cls, api, **kwargs): except requests.exceptions.HTTPError as e: logger.error(f"Error during list request: {e}") # Return an empty list - return [] + + raise_error = kwargs.get('raise_error', False) + + if raise_error: + raise e + else: + return [] if response is None: return [] diff --git a/test/test_order.py b/test/test_order.py index c7111d5..0836567 100644 --- a/test/test_order.py +++ b/test/test_order.py @@ -401,6 +401,14 @@ def test_invalid_list(self): results = order.PurchaseOrder.list(self.api, project_code=999999999) self.assertEqual(len(results), 0) + # Try the same again, but raise the eror + with self.assertRaises(HTTPError): + results = order.PurchaseOrder.list( + self.api, + project_code=999999999, + raise_error=True + ) + # Find a valid project code n = ProjectCode.count(self.api)