Skip to content

Commit

Permalink
Some tweaks in Mouser error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeoLacruz committed Jun 9, 2024
1 parent 85d36b7 commit 765eeff
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion inventree_supplier_panel/supplier_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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, '
Expand Down

0 comments on commit 765eeff

Please sign in to comment.