mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Simpliefy code, return early on error
This commit is contained in:
parent
789eeec777
commit
641486d507
|
@ -38,18 +38,17 @@ QByteArray Toxme::makeJsonRequest(QString url, QString json, QNetworkReply::Netw
|
|||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
QNetworkReply* reply = netman.post(request,json.toUtf8());
|
||||
|
||||
while (reply->isRunning()) {
|
||||
error = reply->error();
|
||||
if (error)
|
||||
break;
|
||||
|
||||
reply->waitForReadyRead(100);
|
||||
while (!reply->isFinished())
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
error = reply->error();
|
||||
if (error)
|
||||
qWarning() << "makeJsonRequest: A network error occured:" << error.errorString();
|
||||
{
|
||||
qWarning() << "makeJsonRequest: A network error occured:" << reply->errorString();
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
return reply->readAll();
|
||||
}
|
||||
|
@ -65,18 +64,17 @@ QByteArray Toxme::getServerPubkey(QString url, QNetworkReply::NetworkError &erro
|
|||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
QNetworkReply* reply = netman.get(request);
|
||||
|
||||
while (reply->isRunning()) {
|
||||
error = reply->error();
|
||||
if (error)
|
||||
break;
|
||||
|
||||
reply->waitForReadyRead(100);
|
||||
while (!reply->isFinished())
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
error = reply->error();
|
||||
if (error)
|
||||
qWarning() << "getServerPubkey: A network error occured:" << error.errorString();
|
||||
{
|
||||
qWarning() << "getServerPubkey: A network error occured:" << reply->errorString();
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
// Extract key
|
||||
static const QByteArray pattern{"key\":\""};
|
||||
|
|
Loading…
Reference in New Issue
Block a user