ZUGFeRD: Validate errors in xml and throw ValidationException

This commit is contained in:
Jonathan Jenne
2023-06-22 10:51:43 +02:00
parent 0da1eb55a9
commit 524c429de4
6 changed files with 139 additions and 129 deletions

View File

@@ -77,14 +77,4 @@ Public Class Exceptions
MyBase.New(pInfo)
End Sub
End Class
Public Class ValidationException
Inherits ApplicationException
Public ValidationErrors As List(Of ZugferdValidationError)
Public Sub New()
MyBase.New("ZUGFeRD document found but validation failed!")
End Sub
End Class
End Class

View File

@@ -255,6 +255,9 @@ Public Class ImportZUGFeRDFiles
Try
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oFile.FullName)
Catch ex As ValidationException
Throw ex
Catch ex As ZUGFeRDExecption
Select Case ex.ErrorType
Case ZUGFeRDInterface.ErrorType.NoZugferd
@@ -267,7 +270,7 @@ Public Class ImportZUGFeRDFiles
Throw New UnsupportedFerdException(ex.XmlFile)
Case ZUGFeRDInterface.ErrorType.NoValidZugferd
_logger.Warn("File [{0}] is an Incorrectly formatted ZUGFeRD document!", oFile.Name)
_logger.Info("File [{0}] is an Incorrectly formatted ZUGFeRD document!", oFile.Name)
Throw New InvalidFerdException()
Case Else
@@ -276,17 +279,6 @@ Public Class ImportZUGFeRDFiles
End Select
End Try
' These validation errors check the document according to the specification.
' Things like this will be checked:
' - Currency Codes
' - Country Codes
' - DateTime Formats
If oDocument.ValidationErrors.Any() Then
Throw New ValidationException() With {
.ValidationErrors = oDocument.ValidationErrors
}
End If
' Extract all attachments with the extensions specified in `AllowedExtensions`.
' If you need to extract and use embedded xml files, you need to filter out the zugferd-invoice.xml yourself.
' Right now the zugferd-invoice.xml is filtered out because `AllowedExtensions` does not contain `xml`.