Improve Error handling across the board

This commit is contained in:
Jonathan Jenne
2022-04-26 12:02:00 +02:00
parent 13af72dee5
commit 3e41502766
19 changed files with 404 additions and 141 deletions

View File

@@ -26,6 +26,8 @@ Namespace Documents
''' </summary>
Public Property Selected As Boolean = False
Private DocumentErrors As New List(Of DocumentError)
Public ReadOnly Property HasErrors As Boolean
Get
Return Errors.Count > 0
@@ -34,8 +36,11 @@ Namespace Documents
Public ReadOnly Property Errors As List(Of String)
Get
Dim oRowErrors = Rows.SelectMany(Function(row) row.Errors).ToList()
Dim oDocumentErrors As List(Of String) = GetDocumentErrors().
Dim oRowErrors = Rows.
SelectMany(Function(row) row.Errors, Function(row, err) err.ToString).
ToList()
Dim oDocumentErrors As List(Of String) = DocumentErrors.
Select(Function(err) err.ToString()).
ToList()
Return oDocumentErrors.
@@ -44,6 +49,13 @@ Namespace Documents
End Get
End Property
Public Sub AddDocumentError(pDocumentError As DocumentErrorType, pMessage As String)
DocumentErrors.Add(New DocumentError With {
.Type = pDocumentError,
.Message = pMessage
})
End Sub
Public ReadOnly Property MandatorId As String
Get
Return Mandator?.Id
@@ -84,19 +96,12 @@ Namespace Documents
End Function
Public Overrides Function Equals(obj As Object) As Boolean
Return FullName = DirectCast(obj, Document).FullName
End Function
Private Function GetDocumentErrors() As List(Of DocumentError)
Dim oErrors As New List(Of DocumentError)
If Mandator Is Nothing Then
oErrors.Add(DocumentError.MandatorNotFound)
If obj Is Nothing Then
Return False
End If
Return oErrors
Return FullName = DirectCast(obj, Document).FullName
End Function
End Class
End Namespace