From e4d2cb83fbf02c272e84ce2997001cfc1ec6a2cf Mon Sep 17 00:00:00 2001 From: ErrorCraft <51973682+ErrorCraft@users.noreply.github.com> Date: Sun, 3 Jan 2021 21:23:37 +0100 Subject: [PATCH] Fix updater always returning null because of a forbidden request --- FunctionAnalyser/CommandFilesApi/Updater.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FunctionAnalyser/CommandFilesApi/Updater.cs b/FunctionAnalyser/CommandFilesApi/Updater.cs index e01c719..47fe330 100644 --- a/FunctionAnalyser/CommandFilesApi/Updater.cs +++ b/FunctionAnalyser/CommandFilesApi/Updater.cs @@ -25,6 +25,7 @@ public Updater(ILogger logger) Client.DefaultRequestHeaders.Accept.Clear(); Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); + Client.DefaultRequestHeaders.UserAgent.TryParseAdd("request"); } public async Task CheckForUpdate() @@ -60,6 +61,7 @@ private async Task GetChangelog(GitHubVersion update) try { GitHubAssets changelogAssets = update.GetAssets().FirstOrDefault(a => a.GetLabel() == CHANGELOG_LABEL); + if (changelogAssets == null) return ""; using HttpResponseMessage response = await Client.GetAsync(changelogAssets.GetDownloadUrl()); if (response.IsSuccessStatusCode) { @@ -68,7 +70,7 @@ private async Task GetChangelog(GitHubVersion update) } catch (HttpRequestException) { } - return null; + return ""; } private static GitHubAssets GetFileAssets(GitHubVersion update)