From 823cb6134b2bad42daf826c5b8570473d1186ab5 Mon Sep 17 00:00:00 2001 From: Ryan Fu <69221034+ryfu-msft@users.noreply.github.com> Date: Thu, 4 Nov 2021 12:23:27 -0700 Subject: [PATCH] Handle taskcanceled exception with error message (#201) * Handle taskcanceled exception with error message * if-else blocks --- src/WingetCreateCLI/Commands/BaseCommand.cs | 17 +++++++++++------ .../Properties/Resources.Designer.cs | 9 +++++++++ src/WingetCreateCLI/Properties/Resources.resx | 3 +++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/WingetCreateCLI/Commands/BaseCommand.cs b/src/WingetCreateCLI/Commands/BaseCommand.cs index 906208d1..fdaa7f10 100644 --- a/src/WingetCreateCLI/Commands/BaseCommand.cs +++ b/src/WingetCreateCLI/Commands/BaseCommand.cs @@ -292,20 +292,25 @@ protected static async Task DownloadPackageFile(string installerUrl) return null; } - - if (e is DownloadSizeExceededException downloadSizeExceededException) + else if (e is DownloadSizeExceededException downloadSizeExceededException) { Logger.ErrorLocalized(nameof(Resources.DownloadFileExceedsMaxSize_Error), $"{downloadSizeExceededException.MaxDownloadSizeInBytes / 1024 / 1024}"); return null; } - - if (e is InvalidOperationException) + else if (e is InvalidOperationException) { Logger.ErrorLocalized(nameof(Resources.InvalidUrl_Error)); return null; } - - throw; + else if (e is TaskCanceledException) + { + Logger.ErrorLocalized(nameof(Resources.DownloadConnectionTimeout_Error)); + return null; + } + else + { + throw; + } } } diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index 24fba7ee..af911f45 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -411,6 +411,15 @@ public static string DoneSymbol_String { } } + /// + /// Looks up a localized string similar to Unable to complete the download request as the connection has timed out. Please verify your installer URL and try again.. + /// + public static string DownloadConnectionTimeout_Error { + get { + return ResourceManager.GetString("DownloadConnectionTimeout_Error", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to download installer.. /// diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index 032d9f94..73a6a3fe 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -783,4 +783,7 @@ Which manifest do you want to edit? + + Unable to complete the download request as the connection has timed out. Please verify your installer URL and try again. + \ No newline at end of file