better handling of invalid zugferd files
This commit is contained in:
@@ -8,6 +8,7 @@ Imports System.Text.RegularExpressions
|
||||
Imports System.Xml
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
Imports DigitalData.Modules.Interfaces.Exceptions
|
||||
Imports DigitalData.Modules.Jobs.Exceptions
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports FirebirdSql.Data.FirebirdClient
|
||||
@@ -260,10 +261,23 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Try
|
||||
oDocument = _zugferd.ExtractZUGFeRDFile(oFile.FullName)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
||||
oFileAttachmentFiles.Add(oFile)
|
||||
Continue For
|
||||
Catch ex As ZUGFeRDExecption
|
||||
Select Case ex.ErrorType
|
||||
Case ZUGFeRDInterface.ErrorType.NoZugferd
|
||||
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
||||
oFileAttachmentFiles.Add(oFile)
|
||||
Continue For
|
||||
|
||||
Case ZUGFeRDInterface.ErrorType.NoValidZugferd
|
||||
_logger.Warn("File is an Incorrectly formatted ZUGFeRD document!")
|
||||
Throw New InvalidFerdException()
|
||||
|
||||
Case Else
|
||||
_logger.Warn("Unexpected Error occurred while extracting ZUGFeRD Information from file {0}", oFile.FullName)
|
||||
Throw ex
|
||||
End Select
|
||||
|
||||
|
||||
End Try
|
||||
|
||||
oMD5CheckSum = CreateMD5(oFile.FullName)
|
||||
@@ -482,6 +496,20 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = "<p>The invoice attached to your email has already been processed in our system.</p>"
|
||||
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||
|
||||
Catch ex As InvalidFerdException
|
||||
_logger.Error(ex)
|
||||
|
||||
oMoveDirectory = args.ErrorDirectory
|
||||
|
||||
Dim oBody = """
|
||||
<p>Your email contained a ZUGFeRD document but it was incorrectly formatted.</p>
|
||||
<p>Possible reasons include:<ul>
|
||||
<li>Amount value has incorrect format (25,01 instead of 25.01)</li>
|
||||
</ul></p>
|
||||
"""
|
||||
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||
Catch ex As TooMuchFerdsException
|
||||
_logger.Error(ex)
|
||||
|
||||
@@ -549,7 +577,7 @@ Public Class ImportZUGFeRDFiles
|
||||
End If
|
||||
End If
|
||||
|
||||
_filesystem.MoveTo(oFile.FullName, oFinalMoveDirectory)
|
||||
_filesystem.MoveTo(oFile.FullName, oFinalMoveDirectory)
|
||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
||||
_logger.Info("File moved to {0}", oFinalMoveDirectory)
|
||||
Next
|
||||
|
||||
@@ -21,6 +21,14 @@ Public Class Exceptions
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class InvalidFerdException
|
||||
Inherits ApplicationException
|
||||
|
||||
Public Sub New()
|
||||
MyBase.New("ZUGFeRD document found but was not formatted correctly")
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class NoFerdsException
|
||||
Inherits ApplicationException
|
||||
|
||||
|
||||
Reference in New Issue
Block a user