diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs
index 8e2832690e4..78fa099c9a8 100644
--- a/Flow.Launcher.Infrastructure/Http/Http.cs
+++ b/Flow.Launcher.Infrastructure/Http/Http.cs
@@ -75,23 +75,31 @@ public static void UpdateProxy(ProxyProperty property)
};
}
- public static async Task Download([NotNull] string url, [NotNull] string filePath)
+ public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath)
{
- using var response = await client.GetAsync(url);
- if (response.StatusCode == HttpStatusCode.OK)
+ try
{
- await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
- await response.Content.CopyToAsync(fileStream);
+ using var response = await client.GetAsync(url);
+ if (response.StatusCode == HttpStatusCode.OK)
+ {
+ await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
+ await response.Content.CopyToAsync(fileStream);
+ }
+ else
+ {
+ throw new HttpRequestException($"Error code <{response.StatusCode}> returned from <{url}>");
+ }
}
- else
+ catch (HttpRequestException e)
{
- throw new HttpRequestException($"Error code <{response.StatusCode}> returned from <{url}>");
+ Log.Exception("Infrastructure.Http", "Http Request Error", e, "DownloadAsync");
+ throw;
}
}
///
/// Asynchrously get the result as string from url.
- /// When supposing the result is long and large, try using GetStreamAsync to avoid reading as string
+ /// When supposing the result larger than 83kb, try using GetStreamAsync to avoid reading as string
///
///
///
@@ -101,19 +109,33 @@ public static Task GetAsync([NotNull] string url)
return GetAsync(new Uri(url.Replace("#", "%23")));
}
+ ///
+ /// Asynchrously get the result as string from url.
+ /// When supposing the result larger than 83kb, try using GetStreamAsync to avoid reading as string
+ ///
+ ///
+ ///
public static async Task GetAsync([NotNull] Uri url)
{
Log.Debug($"|Http.Get|Url <{url}>");
- using var response = await client.GetAsync(url);
- var content = await response.Content.ReadAsStringAsync();
- if (response.StatusCode == HttpStatusCode.OK)
+ try
{
- return content;
+ using var response = await client.GetAsync(url);
+ var content = await response.Content.ReadAsStringAsync();
+ if (response.StatusCode == HttpStatusCode.OK)
+ {
+ return content;
+ }
+ else
+ {
+ throw new HttpRequestException(
+ $"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
+ }
}
- else
+ catch (HttpRequestException e)
{
- throw new HttpRequestException(
- $"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
+ Log.Exception("Infrastructure.Http", "Http Request Error", e, "GetAsync");
+ throw;
}
}
@@ -124,9 +146,17 @@ public static async Task GetAsync([NotNull] Uri url)
///
public static async Task GetStreamAsync([NotNull] string url)
{
- Log.Debug($"|Http.Get|Url <{url}>");
- var response = await client.GetAsync(url);
- return await response.Content.ReadAsStreamAsync();
+ try
+ {
+ Log.Debug($"|Http.Get|Url <{url}>");
+ var response = await client.GetAsync(url);
+ return await response.Content.ReadAsStreamAsync();
+ }
+ catch (HttpRequestException e)
+ {
+ Log.Exception("Infrastructure.Http", "Http Request Error", e, "GetStreamAsync");
+ throw;
+ }
}
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
index 724ddf20d7e..68df5bc1fcb 100644
--- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
+++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
@@ -127,7 +127,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
- await Http.Download(plugin.UrlDownload, filePath).ConfigureAwait(false);
+ await Http.DownloadAsync(plugin.UrlDownload, filePath).ConfigureAwait(false);
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
@@ -217,7 +217,7 @@ on existingPlugin.Metadata.ID equals pluginFromManifest.ID
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
- await Http.Download(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath).ConfigureAwait(false);
+ await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath).ConfigureAwait(false);
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));