Decouple the json timeout from the actual error code.

Fixes #50
This commit is contained in:
Michael Zanetti 2014-10-22 21:43:03 -04:00 committed by Michael Zanetti
parent 71bce5a281
commit de6b60734e
3 changed files with 19 additions and 6 deletions

View File

@ -137,7 +137,8 @@ JsonReply::JsonReply(Type type, JsonHandler *handler, const QString &method, con
m_type(type),
m_data(data),
m_handler(handler),
m_method(method)
m_method(method),
m_timedOut(false)
{
connect(&m_timeout, &QTimer::timeout, this, &JsonReply::timeout);
}
@ -204,7 +205,11 @@ void JsonReply::startWait()
void JsonReply::timeout()
{
m_data.insert("success", false);
m_data.insert("errorMessage", "Command timed out.");
finished();
m_timedOut = true;
emit finished();
}
bool JsonReply::timedOut() const
{
return m_timedOut;
}

View File

@ -53,6 +53,8 @@ public:
int commandId() const;
void setCommandId(int commandId);
bool timedOut() const;
public slots:
void startWait();
@ -71,6 +73,7 @@ private:
QString m_method;
QUuid m_clientId;
int m_commandId;
bool m_timedOut;
QTimer m_timeout;

View File

@ -235,8 +235,13 @@ void JsonRPCServer::sendNotification(const QVariantMap &params)
void JsonRPCServer::asyncReplyFinished()
{
JsonReply *reply = qobject_cast<JsonReply*>(sender());
Q_ASSERT(reply->handler()->validateReturns(reply->method(), reply->data()).first);
sendResponse(reply->clientId(), reply->commandId(), reply->data());
if (!reply->timedOut()) {
Q_ASSERT_X(reply->handler()->validateReturns(reply->method(), reply->data()).first
,"validating return value", formatAssertion(reply->handler()->name(), reply->method(), reply->handler(), reply->data()).toLatin1().data());
sendResponse(reply->clientId(), reply->commandId(), reply->data());
} else {
sendErrorResponse(reply->clientId(), reply->commandId(), "Command timed out");
}
reply->deleteLater();
}