From 966121ece89491cb9bc0e8ee66c01f3c62c50f24 Mon Sep 17 00:00:00 2001 From: EugeneTes Date: Wed, 18 Feb 2026 13:18:19 +0100 Subject: [PATCH] out of paper detection --- .../PrintServer/PrintServices/EpsonPrintService.cs | 11 +++++++++-- Inspectron.Epson/Queue/PrintErrorType.cs | 2 ++ Inspectron.Epson/Queue/PrinterQueue.cs | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs b/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs index 894a8ca..7655651 100644 --- a/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs +++ b/Inspectron.Epson/PrintServer/PrintServices/EpsonPrintService.cs @@ -42,7 +42,8 @@ public class EpsonPrintService: IPrintService var status = await epsonPrinter.GetPrinterStatusAsync(); if (!status.IsOnline) { - throw new InvalidOperationException("Printer is offline or out of paper."); + _logger.LogWarning("Printer {PrinterIp} is out of paper", printerIp); + return PrintResult.Fail(PrintErrorType.OutOfPaper); } var printerAdapter = _wrapperPrinterFactory.CreatePrinterFromId(printerId.Value, epsonPrinter); @@ -101,11 +102,17 @@ public class EpsonPrintService: IPrintService status = await epsonPrinter.GetPrinterStatusAsync(); if (!status.IsOnline) { - throw new InvalidOperationException("Printer is offline or out of paper."); + _logger.LogWarning("Printer {PrinterIp} is out of paper", printerIp); + return PrintResult.Fail(PrintErrorType.OutOfPaper); } await printerAdapter.Cut(); } + catch (EpsonConnectionException e) + { + _logger.LogWarning(e, "Printer {PrinterIp} is offline", printerIp); + return PrintResult.Fail(PrintErrorType.Offline); + } catch (Exception e) { _logger.LogWarning(e, "Failed to print job for printer {PrinterUid}", printerIp); diff --git a/Inspectron.Epson/Queue/PrintErrorType.cs b/Inspectron.Epson/Queue/PrintErrorType.cs index cc255c3..5ac0bf3 100644 --- a/Inspectron.Epson/Queue/PrintErrorType.cs +++ b/Inspectron.Epson/Queue/PrintErrorType.cs @@ -4,5 +4,7 @@ public enum PrintErrorType { None, ConversionError, + Offline, + OutOfPaper, Other } \ No newline at end of file diff --git a/Inspectron.Epson/Queue/PrinterQueue.cs b/Inspectron.Epson/Queue/PrinterQueue.cs index 2583952..d823d9b 100644 --- a/Inspectron.Epson/Queue/PrinterQueue.cs +++ b/Inspectron.Epson/Queue/PrinterQueue.cs @@ -86,6 +86,11 @@ public class PrinterQueue _logger.LogWarning("Job failed due to conversion error, not re-queuing"); await _statusReporter.ReportStatusAsync(job, PrintJobStatus.Failed); } + else if (result.ErrorType == PrintErrorType.Offline) + { + _logger.LogWarning("Printer is offline, job failed"); + await _statusReporter.ReportStatusAsync(job, PrintJobStatus.Failed); + } else { // Re-queue with retry logic