Skip to content

Commit

Permalink
Handle taskcanceled exception with error message (#201)
Browse files Browse the repository at this point in the history
* Handle taskcanceled exception with error message

* if-else blocks
  • Loading branch information
ryfu-msft committed Nov 4, 2021
1 parent 279c063 commit 823cb61
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,25 @@ protected static async Task<string> 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;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -783,4 +783,7 @@
<data name="SelectManifestToEdit_Message" xml:space="preserve">
<value>Which manifest do you want to edit?</value>
</data>
<data name="DownloadConnectionTimeout_Error" xml:space="preserve">
<value>Unable to complete the download request as the connection has timed out. Please verify your installer URL and try again.</value>
</data>
</root>

0 comments on commit 823cb61

Please sign in to comment.