Skip to content

Commit

Permalink
Refactor CatalogPublish error handling. Refs #8538.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Apr 8, 2014
1 parent 78723d5 commit f968514
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Code/Mantid/Framework/ICat/src/CatalogPublish.cpp
Expand Up @@ -138,6 +138,9 @@ namespace Mantid
*/
void CatalogPublish::publish(std::istream& fileContents, const std::string &uploadURL)
{
// Created outside try as we need to throw a runtime later.
// Poco::Exception eats the runtime, then throws an I/O exception due to bug noted below.
std::string IDSError = "";
try
{
Poco::URI uri(uploadURL);
Expand Down Expand Up @@ -166,17 +169,7 @@ namespace Mantid
// Obtain the status returned by the server to verify if it was a success.
Poco::Net::HTTPResponse::HTTPStatus HTTPStatus = response.getStatus();
// The error message returned by the IDS (if one exists).
std::string IDSError = CatalogAlgorithmHelper().getIDSError(HTTPStatus, responseStream);
// Cancel the algorithm and display the message if it exists.
if(!IDSError.empty())
{
// As an error occurred we must cancel the algorithm.
// We cannot throw an exception here otherwise it is caught below as Poco::Exception catches runtimes,
// and then the I/O error is thrown as it is generated above first.
this->cancel();
// Output an appropriate error message from the JSON object returned by the IDS.
g_log.error(IDSError);
}
IDSError = CatalogAlgorithmHelper().getIDSError(HTTPStatus, responseStream);
}
catch(Poco::Net::SSLException& error)
{
Expand All @@ -185,6 +178,9 @@ namespace Mantid
// This is bad, but is needed to catch a POCO I/O error.
// For more info see comments (of I/O error) in CatalogDownloadDataFiles.cpp
catch(Poco::Exception&) {}

// Cancel the algorithm and display the message if it exists.
if(!IDSError.empty()) throw std::runtime_error(IDSError);
}

/**
Expand Down

0 comments on commit f968514

Please sign in to comment.