diff --git a/inventree_supplier_panel/supplier_panel.py b/inventree_supplier_panel/supplier_panel.py index 022f268..bb0b0c1 100644 --- a/inventree_supplier_panel/supplier_panel.py +++ b/inventree_supplier_panel/supplier_panel.py @@ -222,9 +222,11 @@ def update_mouser_cart(self, order, cart_key): url = 'https://api.mouser.com/api/v001/cart/items/insert?apiKey=' + self.get_setting('MOUSERKEY') + '&countryCode=' + country_code header = {'Content-type': 'application/json', 'Accept': 'application/json'} response = Wrappers.post_request(self, json.dumps(cart), url, header) - response = response.json() # Return with error if response was not OK + if response.status_code != 200: + return ({}) + response = response.json() if response['Errors'] != []: self.status_code = 'Mouser answered: ' self.message = response['Errors'][0]['Message'] @@ -281,6 +283,8 @@ def get_mouser_partdata(self, sku): url = 'https://api.mouser.com/api/v1.0/search/partnumber?apiKey=' + self.get_setting('MOUSERSEARCHKEY') header = {'Content-type': 'application/json', 'Accept': 'application/json'} response = Wrappers.post_request(self, json.dumps(part), url, header) + if response.status_code != 200: + return (part_data) response = response.json() if response['Errors'] != []: self.status_code = 'Error, '