Skip to content

Commit

Permalink
Improved messages when downloading from DataHub
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Nov 8, 2023
1 parent abe934d commit 884e0ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions source/FAST/DataHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ static QJsonDocument getJSONFromURL(const std::string& url) {
auto res = reply->readAll();
//std::cout << "Response: " << res.toStdString() << std::endl;
result = QJsonDocument::fromJson(res);
} else if (reply->error() == QNetworkReply::ContentNotFoundError) {
throw Exception("FAST DataHub content not found. Please check spelling.");
} else {
//failure
throw Exception("Error getting JSON data from URL");
throw Exception("Failed to retrieve data from FAST DataHub.\nServer could be down, or you may have no internet access.\nPlease try again later.");
}
return result;
}
Expand Down Expand Up @@ -91,9 +93,11 @@ void DataHub::downloadTextFile(const std::string& url, const std::string& destin
file << result["text"].toString().toStdString();
file.close();
emit progress(fileNr, 100);
} else if (reply->error() == QNetworkReply::ContentNotFoundError) {
throw Exception("FAST DataHub item " + name + " not found. Please check spelling.");
} else {
//failure
throw Exception("Error getting JSON data and pipeline text from URL");
throw Exception("Failed to retrieve data from FAST DataHub.\nServer could be down, or you may have no internet access.\nPlease try again later.");
}
}

Expand Down Expand Up @@ -314,7 +318,7 @@ DataHub::Download DataHub::download(std::string itemID, bool force) {
try {
json = getJSONFromURL(m_URL + "api/items/get/" + itemID);
} catch(Exception &e) {
throw Exception("Unable to get DataHub item with ID " + itemID);
throw e;
}

std::stack<DataHub::Item> toDownload;
Expand Down Expand Up @@ -358,6 +362,7 @@ DataHub::Download DataHub::download(std::string itemID, bool force) {
downloadTextFile(itemObject.downloadURL, folder, downloadName, counter);
} else {
std::cout << "License: " << itemObject.license << std::endl;
std::cout << "Copyright: " << itemObject.copyright << " - " << itemObject.author << std::endl;
if(!itemObject.licenseCustom.empty()) {
std::cout << "Additional license information: " << itemObject.licenseCustom << std::endl;
}
Expand All @@ -377,7 +382,7 @@ bool DataHub::isDownloaded(std::string itemID) {
try {
json = getJSONFromURL(m_URL + "api/items/get/" + itemID);
} catch(Exception &e) {
throw Exception("Unable to get DataHub item with ID " + itemID);
throw e;
}

bool isDownloaded = true;
Expand Down Expand Up @@ -410,7 +415,7 @@ DataHub::Item DataHub::getItem(std::string itemID) {
try {
json = getJSONFromURL(m_URL + "api/items/get/" + itemID);
} catch(Exception &e) {
throw Exception("Unable to get DataHub item with ID " + itemID);
throw e;
}

return DataHub::Item::fromJSON(json.object());
Expand Down

0 comments on commit 884e0ea

Please sign in to comment.