From f6a0022b2406740bb0ba312fc24e44bdd9902e80 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 18 Nov 2024 20:00:17 +0100 Subject: [PATCH] Catching all errors --- .../kotlin/net/codinux/invoicing/mail/MailReader.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt index 39f41be..4d49a87 100644 --- a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt +++ b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt @@ -101,21 +101,20 @@ class MailReader( return null } - private fun tryToReadEInvoice(part: BodyPart): Invoice? { + private fun tryToReadEInvoice(part: BodyPart): Invoice? = try { val filename = part.fileName.lowercase() val contentType = part.contentType.lowercase() - return if (filename.endsWith(".pdf") || contentType.startsWith("application/pdf") || contentType.startsWith("application/octet-stream")) { - try { - eInvoiceReader.extractFromPdf(part.inputStream) - } catch (e: Throwable) { - null - } + if (filename.endsWith(".pdf") || contentType.startsWith("application/pdf") || contentType.startsWith("application/octet-stream")) { + eInvoiceReader.extractFromPdf(part.inputStream) } else if (filename.endsWith(".xml") || contentType.startsWith("application/xml") || contentType.startsWith("text/xml")) { eInvoiceReader.readFromXml(part.inputStream) } else { null } + } catch (e: Throwable) { + log.debug(e) { "Could not extract invoices from ${part.fileName}" } + null } // TODO: same code as in MustangMapper