Try another server if we get an error when executing an RPC, possibly fixes #119
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include "../lib/silentdragonlitelib.h"
|
#include "../lib/silentdragonlitelib.h"
|
||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
#include "sdl.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -357,15 +358,39 @@ QString litelib_process_response(char* resp)
|
|||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
void Executor::run()
|
void Executor::run()
|
||||||
{
|
{
|
||||||
char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
|
||||||
QString reply = litelib_process_response(resp);
|
DEBUG("cmd=" << cmd << " args=" << args << " server=" << config->server);
|
||||||
|
QString response = "";
|
||||||
|
try {
|
||||||
|
char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
||||||
|
response = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEBUG("ignoring exception: " << e.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.toUpper().trimmed() != "OK") {
|
||||||
|
config->server = Settings::getRandomServer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
char* resp = litelib_initialize_existing(
|
||||||
|
config->dangerous,
|
||||||
|
config->server.toStdString().c_str()
|
||||||
|
);
|
||||||
|
response = litelib_process_response(resp);
|
||||||
|
resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
||||||
|
response = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEBUG("server= " << config->server << " gave exception: " << e.what() );
|
||||||
|
emit handleError(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
auto parsed = json::parse(
|
auto parsed = json::parse(
|
||||||
reply.toStdString().c_str(),
|
response.toStdString().c_str(),
|
||||||
nullptr,
|
nullptr,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (parsed.is_discarded() || parsed.is_null()) {
|
if (parsed.is_discarded() || parsed.is_null()) {
|
||||||
emit handleError(reply);
|
emit handleError(response);
|
||||||
} else {
|
} else {
|
||||||
emit responseReady(parsed);
|
emit responseReady(parsed);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user