out of paper detection

This commit is contained in:
EugeneTes
2026-02-18 13:18:19 +01:00
parent 59d7bd750a
commit 966121ece8
3 changed files with 16 additions and 2 deletions

View File

@@ -42,7 +42,8 @@ public class EpsonPrintService: IPrintService
var status = await epsonPrinter.GetPrinterStatusAsync(); var status = await epsonPrinter.GetPrinterStatusAsync();
if (!status.IsOnline) 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); var printerAdapter = _wrapperPrinterFactory.CreatePrinterFromId(printerId.Value, epsonPrinter);
@@ -101,11 +102,17 @@ public class EpsonPrintService: IPrintService
status = await epsonPrinter.GetPrinterStatusAsync(); status = await epsonPrinter.GetPrinterStatusAsync();
if (!status.IsOnline) 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(); await printerAdapter.Cut();
} }
catch (EpsonConnectionException e)
{
_logger.LogWarning(e, "Printer {PrinterIp} is offline", printerIp);
return PrintResult.Fail(PrintErrorType.Offline);
}
catch (Exception e) catch (Exception e)
{ {
_logger.LogWarning(e, "Failed to print job for printer {PrinterUid}", printerIp); _logger.LogWarning(e, "Failed to print job for printer {PrinterUid}", printerIp);

View File

@@ -4,5 +4,7 @@ public enum PrintErrorType
{ {
None, None,
ConversionError, ConversionError,
Offline,
OutOfPaper,
Other Other
} }

View File

@@ -86,6 +86,11 @@ public class PrinterQueue
_logger.LogWarning("Job failed due to conversion error, not re-queuing"); _logger.LogWarning("Job failed due to conversion error, not re-queuing");
await _statusReporter.ReportStatusAsync(job, PrintJobStatus.Failed); 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 else
{ {
// Re-queue with retry logic // Re-queue with retry logic