mirror-chatterino2/src/common/NetworkResult.hpp
pajlada 0e66b17ff0
Add Network tests (#2304)
Also changes the way timeouts happen, since right now if a timeout was met (which it mostly wasn't), it would run the error callback twice causing potentially undefined behaviour
2020-12-26 12:42:39 +01:00

32 lines
807 B
C++

#pragma once
#include <rapidjson/document.h>
#include <QJsonArray>
#include <QJsonObject>
namespace chatterino {
class NetworkResult
{
public:
NetworkResult(const QByteArray &data, int status);
/// Parses the result as json and returns the root as an object.
/// Returns empty object if parsing failed.
QJsonObject parseJson() const;
/// Parses the result as json and returns the root as an array.
/// Returns empty object if parsing failed.
QJsonArray parseJsonArray() const;
/// Parses the result as json and returns the document.
rapidjson::Document parseRapidJson() const;
const QByteArray &getData() const;
int status() const;
static constexpr int timedoutStatus = -2;
private:
QByteArray data_;
int status_;
};
} // namespace chatterino