From 65779731fda904061f345625b52f1eb1602920e2 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 28 Aug 2024 17:04:04 +0200 Subject: [PATCH] Show the content of the message info from the failure exception --- src/BreCalClient/MainWindow.xaml.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 475c8ac..2e848b1 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -23,6 +23,8 @@ using Polly; using System.Net.Http; using System.Net; using System.Windows.Input; +using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; namespace BreCalClient @@ -1058,13 +1060,27 @@ namespace BreCalClient private void ShowErrorDialog(string message, string caption) { + // Example: + // Error calling ShipcallUpdate: {\"message\": \"PUT Requests for shipcalls can only be issued by an assigned AGENCY or BSMD users + // (if the special-flag is enabled). Assigned Agency: ShipcallParticipantMap(id=628, shipcall_id=115, participant_id=10, + // type=8, created=datetime.datetime(2024, 8, 28, 15, 13, 14), modified=None) with Flags: 42\"} + Match m = Regex.Match(message, "\\{(.*)\\}"); + if ((m != null) && (m.Success)) + { + dynamic? msg = JsonConvert.DeserializeObject(m.Value); + if(msg != null) + { + message = msg.message; + } + } + _log.ErrorFormat("{0} - {1}", caption, message); - /* + Dispatcher.Invoke(new Action(() => { MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error); })); - */ + } private void EnableControlsForParticipant()