Modules.Interfaces & Modules.Jobs: Weitergabe der ErrorCodes in den Exceptions, um sie im WebService auswerten zu können.

This commit is contained in:
2025-08-08 11:46:21 +02:00
parent d7d2ecf8a0
commit 2007bb91f3
7 changed files with 119 additions and 58 deletions

View File

@@ -43,7 +43,7 @@ Public Class ZUGFeRDInterface
Private AllowedFilenames As New List(Of String)
Public Enum ErrorType
Public Enum ErrorType1
NoValidFile
NoZugferd
NoValidZugferd
@@ -51,6 +51,7 @@ Public Class ZUGFeRDInterface
UnsupportedFormat
FileTooBig
UnknownError
NotInUse
End Enum
Public ReadOnly Property FileGroup As FileGroups
@@ -171,6 +172,7 @@ Public Class ZUGFeRDInterface
Public Function GetSerializedXMLContentFromFile(oFileInfo As FileInfo) As ZugferdResult
Dim oResult = New ZugferdResult()
Dim oMessage As String = String.Empty
Try
Dim oFileSize As Integer = oFileInfo.Length
@@ -195,7 +197,7 @@ Public Class ZUGFeRDInterface
Catch ex As Exception
_logger.Error(ex)
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, "Datei ist eine ungültige XML Datei.")
Throw New ZUGFeRDExecption(ErrorCodes.UnsupportedFerdException, "Datei ist eine ungültige XML Datei.")
End Try
If oResult.ValidationErrors.Any() Then
@@ -211,7 +213,6 @@ Public Class ZUGFeRDInterface
''' Validates a ZUGFeRD File and extracts the XML Document from it
''' </summary>
''' <param name="Path"></param>
''' <exception cref="ZUGFeRDExecption"></exception>
Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As ZugferdResult
Dim oResult = ValidateZUGFeRDFileWithGDPicture(Path)
oResult = ValidateZUGFeRDDocument(oResult)
@@ -229,7 +230,6 @@ Public Class ZUGFeRDInterface
''' Validates a ZUGFeRD File and extracts the XML Document from it
''' </summary>
''' <param name="Stream"></param>
''' <exception cref="ZUGFeRDExecption"></exception>
Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As ZugferdResult
Dim oResult = ValidateZUGFeRDFileWithGDPicture(Stream)
oResult = ValidateZUGFeRDDocument(oResult)
@@ -252,7 +252,6 @@ Public Class ZUGFeRDInterface
''' Validates a ZUGFeRD File and extracts the XML Document from it
''' </summary>
''' <param name="pStream"></param>
''' <exception cref="ZUGFeRDExecption"></exception>
''' <returns>The embedded xml data as an XPath document</returns>
Public Function ValidateZUGFeRDFileWithGDPicture(pStream As Stream) As ZugferdResult
Dim oEmbedExtractor = New PDFEmbeds(_logConfig)
@@ -281,7 +280,6 @@ Public Class ZUGFeRDInterface
''' Validates a ZUGFeRD File and extracts the XML Document from it
''' </summary>
''' <param name="pPath"></param>
''' <exception cref="ZUGFeRDExecption"></exception>
''' <returns>The embedded xml data as an XPath document</returns>
Public Function ValidateZUGFeRDFileWithGDPicture(pPath As String) As ZugferdResult
Dim oEmbedExtractor = New PDFEmbeds(_logConfig)
@@ -307,12 +305,8 @@ Public Class ZUGFeRDInterface
End Function
Private Function HandleEmbeddedFiles(pResults As List(Of PDFEmbeds.EmbeddedFile)) As ZugferdResult
If pResults Is Nothing Then
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei, weil die Attachments nicht gelesen werden konnten.")
End If
If pResults.Count = 0 Then
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei, weil sie keine Attachments enthält.")
If pResults Is Nothing OrElse pResults.Count = 0 Then
Throw New ZUGFeRDExecption(ErrorCodes.InvalidFerdNoXMLAttachmentFound, "Die Datei ist keine gültige ZUGFeRD-Datei, es wurde kein passender XML-Anhang gefunden.")
End If
' Find the first file which filename matches the valid filenames for embedded invoice files
@@ -321,7 +315,7 @@ Public Class ZUGFeRDInterface
FirstOrDefault()
If oValidResult Is Nothing Then
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei, weil keine entsprechende XML-Datei gefunden wurde.")
Throw New ZUGFeRDExecption(ErrorCodes.InvalidFerdNoXMLAttachmentFound, "Die Datei ist keine ZUGFeRD Datei, weil keine passende XML-Datei gefunden wurde.")
End If
' Search the embedded files for the ones which are allowed as per the configuration.
@@ -331,7 +325,7 @@ Public Class ZUGFeRDInterface
FirstOrDefault()
If oAllowedResult Is Nothing Then
Throw New ZUGFeRDExecption(ErrorType.UnsupportedFormat, "Datei ist eine ZUGFeRD Datei, aber das Format wird nicht unterstützt.", oAllowedResult.FileName)
Throw New ZUGFeRDExecption(ErrorCodes.InvalidFerdNoXMLAttachmentFound, "Datei enthält einen XML-Anhang mit einem ungültigen Dateinamen.", oAllowedResult.FileName)
End If
Try
@@ -349,7 +343,7 @@ Public Class ZUGFeRDInterface
Catch ex As Exception
_logger.Error(ex)
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, "Datei ist eine ungültige ZUGFeRD Datei.")
Throw New ZUGFeRDExecption(ErrorCodes.InvalidFerdException, "XML-Datei konnte nicht gelesen werden.")
End Try
End Function
@@ -456,8 +450,7 @@ Public Class ZUGFeRDInterface
Next
If oObject Is Nothing Then
'Throw New ApplicationException("No Types matched the given document. Document could not be serialized.")
Throw New ZUGFeRDExecption(ErrorType.UnsupportedFormat, "Unsupported Format")
Throw New ZUGFeRDExecption(ErrorCodes.UnsupportedFerdException, "Unsupported Format")
End If
pResult.Specification = oSpecification
@@ -472,8 +465,8 @@ Public Class ZUGFeRDInterface
Catch ex As Exception
_logger.Error(ex)
Dim oMessage = "Datei ist eine ungültige eInvoice Datei oder das Format wird nicht unterstüzt, oder das Format ist deaktiviert."
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, oMessage)
Dim oMessage = "Datei ist eine ungültige Datei oder das Format wird nicht unterstüzt, oder das Format ist deaktiviert."
Throw New ZUGFeRDExecption(ErrorCodes.UnsupportedFerdException, oMessage)
End Try
End Function
End Class