From 1e709f6b35b32e8667e9534aeff30bf6434fde27 Mon Sep 17 00:00:00 2001
From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com>
Date: Sat, 5 Apr 2025 01:20:44 +0100
Subject: [PATCH] add post exception v2
---
Bloxstrap/App.xaml.cs | 20 +++++++++++++------
Bloxstrap/GlobalUsings.cs | 1 +
.../Models/Web/PostExceptionV2Request.cs | 14 +++++++++++++
.../Settings/Pages/BloxstrapPage.xaml | 9 ++++++++-
.../ViewModels/Settings/BloxstrapViewModel.cs | 9 ++++++++-
5 files changed, 45 insertions(+), 8 deletions(-)
create mode 100644 Bloxstrap/Models/Web/PostExceptionV2Request.cs
diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs
index 81cecce..72ca039 100644
--- a/Bloxstrap/App.xaml.cs
+++ b/Bloxstrap/App.xaml.cs
@@ -1,4 +1,5 @@
-using System.Reflection;
+using System.Net.Http.Json;
+using System.Reflection;
using System.Security.Cryptography;
using System.Windows;
using System.Windows.Shell;
@@ -125,7 +126,7 @@ namespace Bloxstrap
_showingExceptionDialog = true;
- SendLog();
+ SendLog(ex);
if (Bootstrapper?.Dialog != null)
{
@@ -198,16 +199,23 @@ namespace Bloxstrap
}
}
- public static async void SendLog()
+ public static async void SendLog(Exception exception)
{
if (!Settings.Prop.EnableAnalytics || !CanSendLogs())
return;
+ var request = new PostExceptionV2Request
+ {
+ Type = exception.GetType().ToString(),
+ Message = exception.Message,
+ Log = Logger.AsDocument
+ };
+
try
{
- await HttpClient.PostAsync(
- $"https://{WebUrl}/metrics/post-exception",
- new StringContent(Logger.AsDocument)
+ await HttpClient.PostAsJsonAsync(
+ $"https://{WebUrl}/metrics/post-exception-v2",
+ request
);
}
catch (Exception ex)
diff --git a/Bloxstrap/GlobalUsings.cs b/Bloxstrap/GlobalUsings.cs
index c04aec2..f380d23 100644
--- a/Bloxstrap/GlobalUsings.cs
+++ b/Bloxstrap/GlobalUsings.cs
@@ -27,6 +27,7 @@ global using Bloxstrap.Models.Manifest;
global using Bloxstrap.Models.Persistable;
global using Bloxstrap.Models.SettingTasks;
global using Bloxstrap.Models.SettingTasks.Base;
+global using Bloxstrap.Models.Web;
global using Bloxstrap.Resources;
global using Bloxstrap.UI;
global using Bloxstrap.Utility;
\ No newline at end of file
diff --git a/Bloxstrap/Models/Web/PostExceptionV2Request.cs b/Bloxstrap/Models/Web/PostExceptionV2Request.cs
new file mode 100644
index 0000000..ce3b0d7
--- /dev/null
+++ b/Bloxstrap/Models/Web/PostExceptionV2Request.cs
@@ -0,0 +1,14 @@
+namespace Bloxstrap.Models.Web
+{
+ internal class PostExceptionV2Request
+ {
+ [JsonPropertyName("type")]
+ public string Type { get; set; } = "";
+
+ [JsonPropertyName("message")]
+ public string Message { get; set; } = "";
+
+ [JsonPropertyName("log")]
+ public string Log { get; set; } = "";
+ }
+}
diff --git a/Bloxstrap/UI/Elements/Settings/Pages/BloxstrapPage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/BloxstrapPage.xaml
index 75d050e..5b23fa8 100644
--- a/Bloxstrap/UI/Elements/Settings/Pages/BloxstrapPage.xaml
+++ b/Bloxstrap/UI/Elements/Settings/Pages/BloxstrapPage.xaml
@@ -31,13 +31,20 @@
+
+
+
+
diff --git a/Bloxstrap/UI/ViewModels/Settings/BloxstrapViewModel.cs b/Bloxstrap/UI/ViewModels/Settings/BloxstrapViewModel.cs
index b1eb626..8154dd4 100644
--- a/Bloxstrap/UI/ViewModels/Settings/BloxstrapViewModel.cs
+++ b/Bloxstrap/UI/ViewModels/Settings/BloxstrapViewModel.cs
@@ -28,14 +28,21 @@ namespace Bloxstrap.UI.ViewModels.Settings
set => App.Settings.Prop.WebEnvironment = value;
}
- public Visibility WebEnvironmentVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed;
+ public Visibility DeveloperOptionVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed;
public bool ShouldExportConfig { get; set; } = true;
public bool ShouldExportLogs { get; set; } = true;
+ public ICommand DebugCrashCommand => new RelayCommand(DebugCrash);
+
public ICommand ExportDataCommand => new RelayCommand(ExportData);
+ private void DebugCrash()
+ {
+ throw new ApplicationException("Pretend like something terrible has happened");
+ }
+
private void ExportData()
{
string timestamp = DateTime.UtcNow.ToString("yyyyMMdd'T'HHmmss'Z'");