From 934f766cf3b25298eb26e411cacf22ca4550beb9 Mon Sep 17 00:00:00 2001 From: n07070 Date: Tue, 26 May 2026 23:53:26 +0200 Subject: [PATCH] Update waiting time, update Exceptions --- src/printer.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/printer.py b/src/printer.py index 82fa990..bbd0514 100644 --- a/src/printer.py +++ b/src/printer.py @@ -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