diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-18 14:18:45 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-19 08:35:03 +0900 |
commit | af0c8135afce32d9e06cc2446d9c675693d2c5fb (patch) | |
tree | 3f75c0a72225b87c2b15144f178437cc79298ff5 /lib/jobs/basejob.cpp | |
parent | 06edc1033427ca96f03954d810aef33e5c940597 (diff) | |
download | libquotient-af0c8135afce32d9e06cc2446d9c675693d2c5fb.tar.gz libquotient-af0c8135afce32d9e06cc2446d9c675693d2c5fb.zip |
BaseJob::rawDataSample()
A new recommended (and localisable) way of getting a piece of raw
response to display next to error messages as "details".
BaseJob::rawData() returns exactly the trimmed piece of data, no
"truncated" suffix there anymore.
Diffstat (limited to 'lib/jobs/basejob.cpp')
-rw-r--r-- | lib/jobs/basejob.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index b21173ae..4a7780b1 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -426,8 +426,8 @@ BaseJob::Status BaseJob::parseReply(QNetworkReply* reply) const auto& json = QJsonDocument::fromJson(d->rawResponse, &error); if( error.error == QJsonParseError::NoError ) return parseJson(json); - else - return { IncorrectResponseError, error.errorString() }; + + return { IncorrectResponseError, error.errorString() }; } BaseJob::Status BaseJob::parseJson(const QJsonDocument&) @@ -519,8 +519,19 @@ BaseJob::Status BaseJob::status() const QByteArray BaseJob::rawData(int bytesAtMost) const { - return bytesAtMost > 0 && d->rawResponse.size() > bytesAtMost ? - d->rawResponse.left(bytesAtMost) + "...(truncated)" : d->rawResponse; + return bytesAtMost > 0 && d->rawResponse.size() > bytesAtMost + ? d->rawResponse.left(bytesAtMost) : d->rawResponse; +} + +QString BaseJob::rawDataSample(int bytesAtMost) const +{ + auto data = rawData(bytesAtMost); + Q_ASSERT(data.size() <= d->rawResponse.size()); + return data.size() == d->rawResponse.size() + ? data : data + tr("...(truncated, %Ln bytes in total)", + "Comes after trimmed raw network response", + d->rawResponse.size()); + } QString BaseJob::statusCaption() const |