From 1ca1ffc6294ce7e92dee414fbfc4fde6b991e70c Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Mon, 17 Mar 2025 01:22:27 +0100 Subject: [PATCH] fix: Remove reading from replay leading to crash (#142) --- llmcore/RequestHandler.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/llmcore/RequestHandler.cpp b/llmcore/RequestHandler.cpp index 98067d3..af8de31 100644 --- a/llmcore/RequestHandler.cpp +++ b/llmcore/RequestHandler.cpp @@ -54,21 +54,24 @@ void RequestHandler::sendLLMRequest(const LLMConfig &config, const QJsonObject & connect(reply, &QNetworkReply::readyRead, this, [this, reply, request, config]() { handleLLMResponse(reply, request, config); }); - connect(reply, &QNetworkReply::finished, this, [manager]() { manager->deleteLater(); }); - connect(reply, &QNetworkReply::finished, this, [this, reply, requestId]() { - reply->deleteLater(); + connect(reply, &QNetworkReply::finished, this, [this, reply, requestId, manager]() { m_activeRequests.remove(requestId); if (reply->error() != QNetworkReply::NoError) { - LOG_MESSAGE(QString("Error details: %1\nStatus code: %2\nResponse: %3") - .arg(reply->errorString()) - .arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()) - .arg(QString(reply->readAll()))); - emit requestFinished(requestId, false, reply->errorString()); + QString errorMessage = reply->errorString(); + int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + LOG_MESSAGE( + QString("Error details: %1\nStatus code: %2").arg(errorMessage).arg(statusCode)); + + emit requestFinished(requestId, false, errorMessage); } else { LOG_MESSAGE("Request finished successfully"); emit requestFinished(requestId, true, QString()); } + + reply->deleteLater(); + manager->deleteLater(); }); }