feat(feedback): optionally include last exception

This commit is contained in:
goat 2021-09-27 23:49:45 +02:00
parent 689b8fa847
commit ef16e346c6
No known key found for this signature in database
GPG key ID: F18F057873895461
3 changed files with 21 additions and 4 deletions

View file

@ -22,7 +22,7 @@ namespace Dalamud.Support
/// <param name="content">The content of the feedback.</param>
/// <param name="reporter">The reporter name.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SendFeedback(PluginManifest plugin, string content, string reporter)
public static async Task SendFeedback(PluginManifest plugin, string content, string reporter, bool includeException)
{
if (content.IsNullOrWhitespace())
return;
@ -37,6 +37,9 @@ namespace Dalamud.Support
Version = plugin.AssemblyVersion.ToString(),
};
if (includeException)
model.Exception = Troubleshooting.LastException?.ToString();
var postContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await client.PostAsync(BugBaitUrl, postContent);
@ -56,6 +59,9 @@ namespace Dalamud.Support
[JsonProperty("reporter")]
public string? Reporter { get; set; }
[JsonProperty("exception")]
public string? Exception { get; set; }
}
}
}

View file

@ -19,6 +19,11 @@ namespace Dalamud.Support
/// </summary>
public static class Troubleshooting
{
/// <summary>
/// Gets the most recent exception to occur.
/// </summary>
public static Exception? LastException { get; private set; }
/// <summary>
/// Log the last exception in a parseable format to serilog.
/// </summary>
@ -26,6 +31,8 @@ namespace Dalamud.Support
/// <param name="context">Additional context.</param>
public static void LogException(Exception exception, string context)
{
LastException = exception;
try
{
var payload = new ExceptionPayload