Skip to content

Commit 37bf324

Browse files
committed
Fix sloppy error handling when component fails to download
1 parent a492264 commit 37bf324

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

FlashpointInstaller/src/Forms/Operate.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ private async void Operation_Load(object sender, EventArgs e)
6161
{
6262
stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(component.URL)));
6363
}
64-
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
64+
catch (WebException ex)
6565
{
66-
client.Dispose();
66+
if (ex.Status != WebExceptionStatus.RequestCanceled)
67+
{
68+
MessageBox.Show(
69+
$"The {workingComponent.Title} component failed to download.\n\n" +
70+
"If this issue persists, please let us know as soon as possible.",
71+
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
72+
);
73+
}
74+
6775
cancelStatus = 2;
76+
CancelButton.PerformClick();
6877
return;
6978
}
7079
}
@@ -253,7 +262,7 @@ await Task.Run(() =>
253262

254263
private async void CancelButton_Click(object sender, EventArgs e)
255264
{
256-
cancelStatus = 1;
265+
if (cancelStatus < 1) cancelStatus = 1;
257266

258267
CancelButton.Enabled = false;
259268
ProgressLabel.Invoke((MethodInvoker)delegate

FlashpointManager/src/Forms/Operate.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ private async void Operation_Load(object sender, EventArgs e)
9696
{
9797
stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(component.URL)));
9898
}
99-
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
99+
catch (WebException ex)
100100
{
101-
client.Dispose();
101+
if (ex.Status != WebExceptionStatus.RequestCanceled)
102+
{
103+
FPM.GenericError(
104+
$"The {workingComponent.Title} component failed to download.\n\n" +
105+
"If this issue persists, please let us know as soon as possible."
106+
);
107+
}
108+
102109
cancelStatus = 2;
110+
CancelButton.PerformClick();
103111
return;
104112
}
105113
}
@@ -325,7 +333,7 @@ void MoveDelete(string source, string dest)
325333

326334
private async void CancelButton_Click(object sender, EventArgs e)
327335
{
328-
cancelStatus = 1;
336+
if (cancelStatus < 1) cancelStatus = 1;
329337

330338
CancelButton.Enabled = false;
331339
ProgressLabel.Invoke((MethodInvoker)delegate

0 commit comments

Comments
 (0)