Skip to content

Commit a0e2022

Browse files
committed
Improve error handling in PluginInstaller for failed HTTP requests
1 parent 3cbbd21 commit a0e2022

2 files changed

Lines changed: 62 additions & 25 deletions

File tree

Source/UI/PluginInstaller.cpp

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,12 @@ void PluginListBoxComponent::run()
669669
String response = URL (baseUrl).readEntireTextStream();
670670

671671
if (response.isEmpty())
672-
LOGE ("Unable to fetch plugins! Please check your internet connection and try again.")
672+
{
673+
String errorMsg = "Unable to fetch plugins! Please check your internet connection and try again.";
674+
LOGE (errorMsg);
675+
MessageManager::callAsync ([this, errorMsg]
676+
{ pluginInfoPanel.updateStatusMessage (errorMsg, true); });
677+
}
673678

674679
var gatewayData;
675680
Result result = JSON::parse (response, gatewayData);
@@ -1124,11 +1129,16 @@ void PluginInfoComponent::run()
11241129
}
11251130
else if (retCode == HTTP_ERR)
11261131
{
1132+
String httpErr = "Please check your internet connection...";
1133+
1134+
if (httpStatusCode != 0)
1135+
httpErr = "Status Code: " + String (httpStatusCode);
1136+
11271137
showAlertOnMessageThread (AlertWindow::WarningIcon,
11281138
"[Plugin Installer] " + pInfo.dependencies[i],
1129-
"HTTP request failed!!\nPlease check your internet connection...");
1139+
"HTTP request failed!!\n" + httpErr);
11301140

1131-
LOGE ("HTTP request failed!! Please check your internet connection...");
1141+
LOGE ("HTTP request failed. ", httpErr);
11321142
return;
11331143
}
11341144
else
@@ -1141,6 +1151,8 @@ void PluginInfoComponent::run()
11411151
LOGE ("Download Failed!!");
11421152
return;
11431153
}
1154+
1155+
httpStatusCode = 0;
11441156
}
11451157

11461158
setStatusMessage ("Downloading " + pInfo.displayName + " ...");
@@ -1151,75 +1163,87 @@ void PluginInfoComponent::run()
11511163

11521164
if (dlReturnCode == SUCCESS)
11531165
{
1166+
LOGC ("Download Successful!");
1167+
11541168
showAlertOnMessageThread (AlertWindow::InfoIcon,
11551169
"[Plugin Installer] " + pInfo.displayName,
11561170
pInfo.displayName + " Installed Successfully");
11571171

1158-
LOGC ("Download Successful!!");
1159-
11601172
updateUIOnMessageThread();
11611173
}
11621174
else if (dlReturnCode == ZIP_NOTFOUND)
11631175
{
1176+
String errMsg = "Download Failed! ZIP file not found.";
1177+
1178+
if (httpStatusCode != 0)
1179+
errMsg += " HTTP Status Code: " + String (httpStatusCode);
1180+
1181+
LOGE (errMsg);
1182+
11641183
showAlertOnMessageThread (AlertWindow::WarningIcon,
11651184
"[Plugin Installer] " + pInfo.displayName,
11661185
"Could not find the ZIP file for " + pInfo.displayName
11671186
+ ". Please contact the developers.");
1168-
1169-
LOGE ("Download Failed!!");
11701187
}
11711188
else if (dlReturnCode == UNCMP_ERR)
11721189
{
1190+
LOGE ("Download Failed! Uncompressing ZIP failed.");
1191+
11731192
showAlertOnMessageThread (AlertWindow::WarningIcon,
11741193
"[Plugin Installer] " + pInfo.displayName,
11751194
"Could not uncompress the ZIP file. Please try again.");
1176-
1177-
LOGE ("Download Failed!!");
11781195
}
11791196
else if (dlReturnCode == XML_MISSING)
11801197
{
1198+
LOGE ("XML File Missing! Please relaunch Plugin Installer.");
1199+
11811200
showAlertOnMessageThread (AlertWindow::WarningIcon,
11821201
"[Plugin Installer] " + pInfo.displayName,
1183-
"Unable to locate installedPlugins.xml \n Please restart Plugin Installer and try again.");
1184-
1185-
LOGE ("XML File Missing!!");
1202+
"Unable to locate installedPlugins.xml \n Please relaunch Plugin Installer and try again.");
11861203
}
11871204
else if (dlReturnCode == VER_EXISTS_ERR)
11881205
{
1206+
LOGE ("Download Failed! Version already exists.");
1207+
11891208
showAlertOnMessageThread (AlertWindow::WarningIcon,
11901209
"[Plugin Installer] " + pInfo.displayName,
11911210
pInfo.displayName + " v" + pInfo.selectedVersion
11921211
+ " already exists. Please download another version.");
1193-
1194-
LOGE ("Download Failed!!");
11951212
}
11961213
else if (dlReturnCode == XML_WRITE_ERR)
11971214
{
1215+
LOGE ("Writing to XML Failed! Please try again.");
1216+
11981217
showAlertOnMessageThread (AlertWindow::WarningIcon,
11991218
"[Plugin Installer] " + pInfo.displayName,
12001219
"Unable to write to installedPlugins.xml \n Please try again.");
1201-
1202-
LOGE ("Writing to XML Failed!!");
12031220
}
12041221
else if (dlReturnCode == LOAD_ERR)
12051222
{
1223+
LOGE ("Loading Plugin Failed!");
1224+
12061225
showAlertOnMessageThread (AlertWindow::WarningIcon,
12071226
"[Plugin Installer] " + pInfo.displayName,
12081227
"Unable to load " + pInfo.displayName
12091228
+ " in the Processor List.\nLook at console output for more details.");
12101229

1211-
LOGE ("Loading Plugin Failed!!");
1212-
12131230
updateUIOnMessageThread();
12141231
}
12151232
else if (dlReturnCode == HTTP_ERR)
12161233
{
1234+
String httpErr = "Please check your internet connection...";
1235+
1236+
if (httpStatusCode != 0)
1237+
httpErr = "Status Code: " + String (httpStatusCode);
1238+
1239+
LOGE ("HTTP request failed. ", httpErr);
1240+
12171241
showAlertOnMessageThread (AlertWindow::WarningIcon,
12181242
"[Plugin Installer] " + pInfo.displayName,
1219-
"HTTP request failed!!\nPlease check your internet connection...");
1220-
1221-
LOGE ("HTTP request failed!! Please check your internet connection...");
1243+
"HTTP request failed!!\n" + httpErr);
12221244
}
1245+
1246+
httpStatusCode = 0;
12231247
}
12241248

12251249
void PluginInfoComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
@@ -1423,11 +1447,19 @@ int PluginInfoComponent::downloadPlugin (const String& plugin, const String& ver
14231447

14241448
// Could not retrieve data
14251449
if (! fileStream)
1426-
return 7;
1450+
return HTTP_ERR;
14271451

1428-
// ZIP file empty, return.
1429-
if (fileStream->getTotalLength() == 0)
1430-
return 0;
1452+
if (auto webStream = dynamic_cast<WebInputStream*> (fileStream.get()))
1453+
{
1454+
httpStatusCode = webStream->getStatusCode();
1455+
if (httpStatusCode >= 400)
1456+
{
1457+
if (httpStatusCode == 404 || fileStream->getTotalLength() < 1)
1458+
return ZIP_NOTFOUND;
1459+
else
1460+
return HTTP_ERR;
1461+
}
1462+
}
14311463

14321464
//Construct path for downloaded zip file
14331465
String pluginFilePath = CoreServices::getSavedStateDirectory().getFullPathName();
@@ -1447,6 +1479,9 @@ int PluginInfoComponent::downloadPlugin (const String& plugin, const String& ver
14471479
//Uncompress zip file contents
14481480
ZipFile pluginZip (pluginFile);
14491481

1482+
if (! pluginFile.exists())
1483+
return ZIP_NOTFOUND;
1484+
14501485
//Get *.dll/*.so name of plugin
14511486
#if JUCE_WINDOWS
14521487
auto entry = pluginZip.getEntry (0);

Source/UI/PluginInstaller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class PluginInfoComponent : public Component,
163163
HTTP_ERR
164164
};
165165

166+
int httpStatusCode = 0;
167+
166168
void run() override;
167169

168170
/** Shows the alert message on the message thread **/

0 commit comments

Comments
 (0)