Elwig: Update Exception usage patterns
This commit is contained in:
1 parent
808e834284
commit
5cdb83601d
19 files changed
+54
-35
No files matched your search
@@ -1,7 +1,9 @@
|
||||
using iText.Commons.Exceptions;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
|
||||
@@ -118,6 +120,7 @@ namespace Elwig.Services {
|
||||
}
|
||||
|
||||
public static void ShowException(string title, string? text, Exception exc, bool showExcType = false, bool isError = true) {
|
||||
bool fatal = false;
|
||||
text = text == null ? "" : text + (text.EndsWith('.') || text.EndsWith('!') || text.EndsWith('?') ? "" : ":") + "\n\n";
|
||||
if ((exc.InnerException ?? exc) is SqliteException sql) {
|
||||
if (sql.SqliteErrorCode == 5 || sql.SqliteErrorCode == 6) {
|
||||
@@ -145,10 +148,14 @@ namespace Elwig.Services {
|
||||
if (exc.InnerException != null) text += "\n\n" + exc.InnerException.Message;
|
||||
}
|
||||
} else {
|
||||
text += exc.Message + (showExcType ? $" ({exc.GetType().Name})" : "");
|
||||
if (exc is SystemException and not FileNotFoundException and not OperationCanceledException and not FileFormatException and not IOException and not TimeoutException || exc is ITextException) {
|
||||
text += "Schwerwiegender Fehler; unbedingt den Programmierern melden:\n\n";
|
||||
fatal = true;
|
||||
}
|
||||
text += exc.Message + (showExcType || fatal ? $" ({exc.GetType().Name})" : "");
|
||||
if (exc.InnerException != null) text += "\n\n" + exc.InnerException.Message;
|
||||
}
|
||||
if (App.Config.Debug && exc.StackTrace != null) {
|
||||
if ((fatal || App.Config.Debug) && exc.StackTrace != null) {
|
||||
var m = Regex.Match(exc.StackTrace, @"\\([^:\\]*):line ([0-9]+)");
|
||||
if (m != null) text += "\n\n" + m.Groups[1] + ": line " + m.Groups[2];
|
||||
}
|
||||
@@ -167,7 +174,11 @@ namespace Elwig.Services {
|
||||
text = text == null ? "" : text + (text.EndsWith('.') || text.EndsWith('!') || text.EndsWith('?') ? "" : ":") + "\n\n";
|
||||
text += exc.Message;
|
||||
if (exc.InnerException != null) text += "\n\n" + exc.InnerException.Message;
|
||||
if (Override != null) {
|
||||
if (NextError != null) {
|
||||
NextError(title, text);
|
||||
NextError = null;
|
||||
return false;
|
||||
} else if (Override != null) {
|
||||
return Override("error", title, text) != null;
|
||||
} else {
|
||||
return MessageBox.Show(text, title, MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.No) == MessageBoxResult.Yes;
|
||||
|
||||
@@ -114,16 +114,16 @@ namespace Elwig.Services {
|
||||
return [];
|
||||
|
||||
TracesCertificate[] certs = [.. jsonCerts.Select(j => new TracesCertificate {
|
||||
Id = j!["reference"]?.GetValue<string>() ?? throw new Exception(),
|
||||
AuthorityCode = j["issuingBody"]?["code"]?.GetValue<string>() ?? throw new Exception(),
|
||||
OperatorId = j["operatorIdentifier"]?.GetValue<string>() ?? throw new Exception(),
|
||||
OperatorName = j["operator"]?["name"]?.GetValue<string>() ?? throw new Exception(),
|
||||
Activities = [.. j["activities"]?.AsArray().Select(a => Enum.Parse<TracesActivity>(a?["id"]?.GetValue<string>().ToUpper().Replace("_IMPORT", "IMPORT") ?? throw new Exception())) ?? []],
|
||||
CategoriesOfProduct = [.. j["categoriesOfProduct"]?.AsArray().Select(c => Enum.Parse<TracesCategoryOfProduct>(c?["id"]?.GetValue<string>() ?? throw new Exception())) ?? []],
|
||||
IssuedOn = DateOnly.FromDateTime(DateTime.ParseExact(j["issuedOn"]?.GetValue<string>() ?? throw new Exception(), "yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture, DateTimeStyles.None)),
|
||||
ExpiresOn = DateOnly.ParseExact(j["expiresOn"]?.GetValue<string>() ?? throw new Exception(), "yyyy-MM-dd"),
|
||||
LastStatusUpdateOn = DateOnly.FromDateTime(DateTime.ParseExact(j["lastStatusUpdateDateTime"]?.GetValue<string>() ?? throw new Exception(), "yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture, DateTimeStyles.None)),
|
||||
Status = Enum.Parse<TracesStatus>(j["status"]?["id"]?.GetValue<string>() ?? throw new Exception()),
|
||||
Id = j!["reference"]?.GetValue<string>() ?? throw new KeyNotFoundException(),
|
||||
AuthorityCode = j["issuingBody"]?["code"]?.GetValue<string>() ?? throw new KeyNotFoundException(),
|
||||
OperatorId = j["operatorIdentifier"]?.GetValue<string>() ?? throw new KeyNotFoundException(),
|
||||
OperatorName = j["operator"]?["name"]?.GetValue<string>() ?? throw new KeyNotFoundException(),
|
||||
Activities = [.. j["activities"]?.AsArray().Select(a => Enum.Parse<TracesActivity>(a?["id"]?.GetValue<string>().ToUpper().Replace("_IMPORT", "IMPORT") ?? throw new KeyNotFoundException())) ?? []],
|
||||
CategoriesOfProduct = [.. j["categoriesOfProduct"]?.AsArray().Select(c => Enum.Parse<TracesCategoryOfProduct>(c?["id"]?.GetValue<string>() ?? throw new KeyNotFoundException())) ?? []],
|
||||
IssuedOn = DateOnly.FromDateTime(DateTime.ParseExact(j["issuedOn"]?.GetValue<string>() ?? throw new KeyNotFoundException(), "yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture, DateTimeStyles.None)),
|
||||
ExpiresOn = DateOnly.ParseExact(j["expiresOn"]?.GetValue<string>() ?? throw new KeyNotFoundException(), "yyyy-MM-dd"),
|
||||
LastStatusUpdateOn = DateOnly.FromDateTime(DateTime.ParseExact(j["lastStatusUpdateDateTime"]?.GetValue<string>() ?? throw new KeyNotFoundException(), "yyyy-MM-ddTHH:mm:ss.fffK", CultureInfo.InvariantCulture, DateTimeStyles.None)),
|
||||
Status = Enum.Parse<TracesStatus>(j["status"]?["id"]?.GetValue<string>() ?? throw new KeyNotFoundException()),
|
||||
})];
|
||||
|
||||
return (!searchedByName || certs.Where(c => c.Status == TracesStatus.ISSUED).Select(c => c.OperatorId).ToHashSet().Count == 1) ? certs : [];
|
||||
|
||||
Reference in new issue
Block a user