Skip to content

Commit

Permalink
Catch network error for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeoLacruz committed Dec 17, 2024
1 parent a1d9dca commit da724ee
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions inventree_zebra/zebra_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ZebraLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
'name': _('Printer Interface'),
'description': _('Select local or network printer'),
'choices': [('local', 'Local printer e.g. USB'),
('preview', 'ZPL preview using labelary.com API'),
('network', 'Network printer with IP address')],
('network', 'Network printer with IP address'),
('preview', 'ZPL preview using labelary.com API')],
'default': 'local',
},
'IP_ADDRESS': {
Expand Down Expand Up @@ -176,11 +176,17 @@ def print_label(self, **kwargs):
elif (connection == 'preview'):
width_inch = round(width / 25.4, 2)
height_inch = round(height / 25.4, 2)
url = f'http://api.labelary.com/v1/printers/{dpmm}dpmm/labels/{width_inch}x{height_inch}/0'
url = f'https://api.labelary.com/v1/printers/{dpmm}dpmm/labels/{width_inch}x{height_inch}/0'
header = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'application/pdf'}
response = Wrappers.post_request(self, li.dumpZPL(), url, header)
if response.status_code == 200:
try:
status_code = response.status_code
except Exception as Error:
status_code = 0
if status_code == 200:
self.preview_result = ContentFile(response.content, 'label.pdf')
elif status_code == 0:
self.preview_result = ContentFile(f'Request error: {response}', 'label.html')
else:
self.preview_result = ContentFile(f'Labalary API Error: {response.content}', 'label.html')
else:
Expand Down

0 comments on commit da724ee

Please sign in to comment.