Update waiting time, update Exceptions
This commit is contained in:
@@ -69,7 +69,7 @@ class Printer(object):
|
||||
|
||||
# TODO: This could happen directly when creating a new Printer class
|
||||
if os.getenv("FLASK_DEBUG"):
|
||||
waiting_elapsed = 15
|
||||
waiting_elapsed = 3
|
||||
else:
|
||||
waiting_elapsed = 10
|
||||
|
||||
@@ -82,19 +82,18 @@ class Printer(object):
|
||||
p = escpos.printer.Usb(
|
||||
self.device_id, self.vendor_id, 0, profile="TM-P80"
|
||||
)
|
||||
except Exception as e:
|
||||
except RuntimeError as e:
|
||||
self.app.logger.error(
|
||||
"The USB device is not plugged in, trying again %s : %s",
|
||||
waiting_elapsed,
|
||||
str(e),
|
||||
)
|
||||
pass
|
||||
|
||||
try:
|
||||
if p.is_online():
|
||||
self.ready = True
|
||||
self.app.logger.debug("Printer online !")
|
||||
except Exception as e:
|
||||
except RuntimeError as e:
|
||||
self.app.logger.error(
|
||||
"Error while getting the printer online %s : %s",
|
||||
waiting_elapsed,
|
||||
@@ -154,7 +153,7 @@ class Printer(object):
|
||||
self.app.logger.warning(
|
||||
"Could not print message of this length: " + str(len(clean_msg))
|
||||
)
|
||||
raise Exception(
|
||||
raise RuntimeError(
|
||||
"Could not print message of this length :"
|
||||
+ str(len(clean_msg))
|
||||
+ ", needs to be below 4096 caracters long."
|
||||
@@ -164,7 +163,7 @@ class Printer(object):
|
||||
self.app.logger.warning(
|
||||
"Could not print signature of this length: " + str(len(clean_signature))
|
||||
)
|
||||
raise Exception(
|
||||
raise RuntimeError(
|
||||
"Could not print signature of this length :"
|
||||
+ str(len(clean_signature))
|
||||
+ ", needs to be below 256 caracters long."
|
||||
@@ -256,7 +255,7 @@ class Printer(object):
|
||||
self.printer.open(self.usb_args)
|
||||
self.printer.qr(content, center=True)
|
||||
self.printer.close()
|
||||
except Exception as e:
|
||||
except RuntimeError as e:
|
||||
self.printer.close()
|
||||
self.app.logger.error(str(e))
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user