mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-28 08:17:18 +00:00
don't duplicate QCoro's exception passing
This commit is contained in:
parent
ea2ced8c8b
commit
068845e1a2
@ -10,7 +10,6 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <exception>
|
|
||||||
#include <expected>
|
#include <expected>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
@ -22,15 +21,8 @@ namespace boost::json { class value; }
|
|||||||
namespace gpt4all::backend {
|
namespace gpt4all::backend {
|
||||||
|
|
||||||
struct ResponseError {
|
struct ResponseError {
|
||||||
private:
|
QNetworkReply::NetworkError error;
|
||||||
using ErrorCode = std::variant<
|
QString errorString;
|
||||||
QNetworkReply::NetworkError,
|
|
||||||
std::exception_ptr
|
|
||||||
>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ErrorCode error;
|
|
||||||
QString errorString;
|
|
||||||
|
|
||||||
ResponseError(const QNetworkReply *reply)
|
ResponseError(const QNetworkReply *reply)
|
||||||
: error(reply->error())
|
: error(reply->error())
|
||||||
@ -38,13 +30,6 @@ public:
|
|||||||
{
|
{
|
||||||
assert(reply->error());
|
assert(reply->error());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseError(const std::exception &e, std::exception_ptr err)
|
|
||||||
: error(std::move(err))
|
|
||||||
, errorString(e.what())
|
|
||||||
{
|
|
||||||
assert(std::get<std::exception_ptr>(error));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -27,20 +27,16 @@ static auto processResponse(QNetworkReply &reply) -> QCoro::Task<DataOrRespErr<j
|
|||||||
if (reply.error())
|
if (reply.error())
|
||||||
co_return std::unexpected(&reply);
|
co_return std::unexpected(&reply);
|
||||||
|
|
||||||
try {
|
json::parser p;
|
||||||
json::parser p;
|
auto coroReply = qCoro(reply);
|
||||||
auto coroReply = qCoro(reply);
|
do {
|
||||||
do {
|
auto chunk = co_await coroReply.readAll();
|
||||||
auto chunk = co_await coroReply.readAll();
|
if (reply.error())
|
||||||
if (reply.error())
|
co_return std::unexpected(&reply);
|
||||||
co_return std::unexpected(&reply);
|
p.write(chunk.data(), chunk.size());
|
||||||
p.write(chunk.data(), chunk.size());
|
} while (!reply.atEnd());
|
||||||
} while (!reply.atEnd());
|
|
||||||
|
|
||||||
co_return p.release();
|
co_return p.release();
|
||||||
} catch (const std::exception &e) {
|
|
||||||
co_return std::unexpected(ResponseError(e, std::current_exception()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user