mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve CommunityPluginSource http exception handler
This commit is contained in:
parent
0d9ec48e58
commit
230df80b87
2 changed files with 41 additions and 19 deletions
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
@ -15,6 +16,8 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
||||||
{
|
{
|
||||||
public record CommunityPluginSource(string ManifestFileUrl)
|
public record CommunityPluginSource(string ManifestFileUrl)
|
||||||
{
|
{
|
||||||
|
private static readonly string ClassName = nameof(CommunityPluginSource);
|
||||||
|
|
||||||
private string latestEtag = "";
|
private string latestEtag = "";
|
||||||
|
|
||||||
private List<UserPlugin> plugins = new();
|
private List<UserPlugin> plugins = new();
|
||||||
|
|
@ -34,36 +37,51 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
|
public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
Log.Info(nameof(CommunityPluginSource), $"Loading plugins from {ManifestFileUrl}");
|
Log.Info(ClassName, $"Loading plugins from {ManifestFileUrl}");
|
||||||
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, ManifestFileUrl);
|
var request = new HttpRequestMessage(HttpMethod.Get, ManifestFileUrl);
|
||||||
|
|
||||||
request.Headers.Add("If-None-Match", latestEtag);
|
request.Headers.Add("If-None-Match", latestEtag);
|
||||||
|
|
||||||
using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token)
|
try
|
||||||
|
{
|
||||||
|
using var response = await Http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (response.StatusCode == HttpStatusCode.OK)
|
if (response.StatusCode == HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
plugins = await response.Content
|
plugins = await response.Content
|
||||||
.ReadFromJsonAsync<List<UserPlugin>>(PluginStoreItemSerializationOption, cancellationToken: token)
|
.ReadFromJsonAsync<List<UserPlugin>>(PluginStoreItemSerializationOption, cancellationToken: token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
latestEtag = response.Headers.ETag?.Tag;
|
latestEtag = response.Headers.ETag?.Tag;
|
||||||
|
|
||||||
Log.Info(nameof(CommunityPluginSource), $"Loaded {plugins.Count} plugins from {ManifestFileUrl}");
|
Log.Info(ClassName, $"Loaded {plugins.Count} plugins from {ManifestFileUrl}");
|
||||||
return plugins;
|
return plugins;
|
||||||
|
}
|
||||||
|
else if (response.StatusCode == HttpStatusCode.NotModified)
|
||||||
|
{
|
||||||
|
Log.Info(ClassName, $"Resource {ManifestFileUrl} has not been modified.");
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn(ClassName,
|
||||||
|
$"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (response.StatusCode == HttpStatusCode.NotModified)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Info(nameof(CommunityPluginSource), $"Resource {ManifestFileUrl} has not been modified.");
|
if (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException)
|
||||||
|
{
|
||||||
|
Log.Exception(ClassName, $"Check your connection and proxy settings to {ManifestFileUrl}.", e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Exception(ClassName, "Error Occurred", e);
|
||||||
|
}
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.Warn(nameof(CommunityPluginSource),
|
|
||||||
$"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
|
|
||||||
throw new Exception($"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,14 @@ namespace Flow.Launcher.Core
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if ((e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException))
|
if (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException)
|
||||||
|
{
|
||||||
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
|
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Log.Exception($"|Updater.UpdateApp|Error Occurred", e);
|
Log.Exception($"|Updater.UpdateApp|Error Occurred", e);
|
||||||
|
}
|
||||||
|
|
||||||
if (!silentUpdate)
|
if (!silentUpdate)
|
||||||
_api.ShowMsg(_api.GetTranslation("update_flowlauncher_fail"),
|
_api.ShowMsg(_api.GetTranslation("update_flowlauncher_fail"),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue