mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixed crash when onError is not set
This commit is contained in:
parent
c42b6f5335
commit
a0e33ef9e6
1 changed files with 26 additions and 22 deletions
|
@ -216,7 +216,7 @@ public:
|
|||
|
||||
if (this->data.caller != nullptr) {
|
||||
QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller,
|
||||
[onFinished, data = this->data](auto reply) mutable {
|
||||
[ onFinished, data = this->data ](auto reply) mutable {
|
||||
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
||||
// TODO: We might want to call an onError callback here
|
||||
return;
|
||||
|
@ -238,7 +238,7 @@ public:
|
|||
|
||||
QObject::connect(
|
||||
&requester, &NetworkRequester::requestUrl, worker,
|
||||
[timer, data = std::move(this->data), worker, onFinished{std::move(onFinished)}]() {
|
||||
[ timer, data = std::move(this->data), worker, onFinished{std::move(onFinished)} ]() {
|
||||
QNetworkReply *reply = NetworkManager::NaM.get(data.request);
|
||||
|
||||
if (timer != nullptr) {
|
||||
|
@ -253,21 +253,21 @@ public:
|
|||
data.onReplyCreated(reply);
|
||||
}
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, worker,
|
||||
[data = std::move(data), worker, reply,
|
||||
onFinished = std::move(onFinished)]() mutable {
|
||||
if (data.caller == nullptr) {
|
||||
QByteArray bytes = reply->readAll();
|
||||
data.writeToCache(bytes);
|
||||
onFinished(bytes);
|
||||
QObject::connect(reply, &QNetworkReply::finished, worker, [
|
||||
data = std::move(data), worker, reply, onFinished = std::move(onFinished)
|
||||
]() mutable {
|
||||
if (data.caller == nullptr) {
|
||||
QByteArray bytes = reply->readAll();
|
||||
data.writeToCache(bytes);
|
||||
onFinished(bytes);
|
||||
|
||||
reply->deleteLater();
|
||||
} else {
|
||||
emit worker->doneUrl(reply);
|
||||
}
|
||||
reply->deleteLater();
|
||||
} else {
|
||||
emit worker->doneUrl(reply);
|
||||
}
|
||||
|
||||
delete worker;
|
||||
});
|
||||
delete worker;
|
||||
});
|
||||
});
|
||||
|
||||
emit requester.requestUrl();
|
||||
|
@ -276,7 +276,7 @@ public:
|
|||
template <typename FinishedCallback>
|
||||
void getJSON(FinishedCallback onFinished)
|
||||
{
|
||||
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool {
|
||||
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes)->bool {
|
||||
auto object = parseJSONFromData(bytes);
|
||||
onFinished(object);
|
||||
|
||||
|
@ -289,7 +289,7 @@ public:
|
|||
template <typename FinishedCallback>
|
||||
void getJSON2(FinishedCallback onFinished)
|
||||
{
|
||||
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool {
|
||||
this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes)->bool {
|
||||
auto object = parseJSONFromData2(bytes);
|
||||
onFinished(object);
|
||||
|
||||
|
@ -369,10 +369,14 @@ private:
|
|||
worker->moveToThread(&NetworkManager::workerThread);
|
||||
|
||||
if (this->data.caller != nullptr) {
|
||||
QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller,
|
||||
[data = this->data](auto reply) mutable {
|
||||
QObject::connect(worker, &NetworkWorker::doneUrl,
|
||||
this->data.caller, [data = this->data](auto reply) mutable {
|
||||
auto &dat = data;
|
||||
|
||||
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
||||
data.onError(reply->error());
|
||||
if (data.onError) {
|
||||
data.onError(reply->error());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -391,7 +395,7 @@ private:
|
|||
}
|
||||
|
||||
QObject::connect(&requester, &NetworkRequester::requestUrl, worker,
|
||||
[timer, data = std::move(this->data), worker]() {
|
||||
[ timer, data = std::move(this->data), worker ]() {
|
||||
QNetworkReply *reply;
|
||||
switch (data.requestType) {
|
||||
case GetRequest: {
|
||||
|
@ -427,7 +431,7 @@ private:
|
|||
}
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, worker,
|
||||
[data = std::move(data), worker, reply]() mutable {
|
||||
[ data = std::move(data), worker, reply ]() mutable {
|
||||
if (data.caller == nullptr) {
|
||||
QByteArray bytes = reply->readAll();
|
||||
data.writeToCache(bytes);
|
||||
|
|
Loading…
Reference in a new issue