In case of error, report the right error instead of missing etag

also, missing etag is not a fatal error
This commit is contained in:
Olivier Goffart 2014-04-22 12:34:03 +02:00
parent 1338c08622
commit 3fac5f91c8
2 changed files with 20 additions and 2 deletions

View file

@ -358,17 +358,25 @@ void GETFileJob::start() {
void GETFileJob::slotMetaDataChanged()
{
qDebug() << Q_FUNC_INFO << reply()->error() << reply()->errorString() << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (reply()->error() != QNetworkReply::NoError ) {
// We will handle the error when the job is finished.
return;
}
QByteArray etag = parseEtag(reply()->rawHeader("Etag"));
if (etag.isEmpty()) {
qDebug() << Q_FUNC_INFO << "No E-Tag reply by server, considering it invalid";
_errorString = tr("No E-Tag received from server, check Proxy/Gateway");
_errorStatus = SyncFileItem::NormalError;
reply()->abort();
return;
} else if (!_expectedEtagForResume.isEmpty() && _expectedEtagForResume != etag) {
qDebug() << Q_FUNC_INFO << "We received a different E-Tag for resuming!"
<< _expectedEtagForResume << "vs" << etag;
_errorString = tr("We received a different E-Tag for resuming. Retrying next time.");
_errorStatus = SyncFileItem::NormalError;
reply()->abort();
return;
}
@ -383,6 +391,7 @@ void GETFileJob::slotReadyRead()
qint64 r = reply()->read(buffer.data(), bufferSize);
if (r < 0) {
_errorString = reply()->errorString();
_errorStatus = SyncFileItem::NormalError;
qDebug() << "Error while reading from device: " << _errorString;
reply()->abort();
return;
@ -391,6 +400,7 @@ void GETFileJob::slotReadyRead()
qint64 w = _device->write(buffer.constData(), r);
if (w != r) {
_errorString = _device->errorString();
_errorStatus = SyncFileItem::NormalError;
qDebug() << "Error while writing to file" << w << r << _errorString;
reply()->abort();
return;
@ -497,7 +507,11 @@ void PropagateDownloadFileQNAM::slotGetFinished()
}
_item._httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
_propagator->_activeJobs--;
done(classifyError(err, _item._httpErrorCode), job->errorString());
SyncFileItem::Status status = job->errorStatus();
if (status == SyncFileItem::NoStatus) {
status = classifyError(err, _item._httpErrorCode);
}
done(status, job->errorString());
return;
}

View file

@ -101,6 +101,7 @@ class GETFileJob : public AbstractNetworkJob {
QMap<QByteArray, QByteArray> _headers;
QString _errorString;
QByteArray _expectedEtagForResume;
SyncFileItem::Status _errorStatus;
public:
// DOES NOT take owncership of the device.
@ -108,7 +109,8 @@ public:
const QMap<QByteArray, QByteArray> &headers, QByteArray expectedEtagForResume,
QObject* parent = 0)
: AbstractNetworkJob(account, path, parent),
_device(device), _headers(headers), _expectedEtagForResume(expectedEtagForResume) {}
_device(device), _headers(headers), _expectedEtagForResume(expectedEtagForResume),
_errorStatus(SyncFileItem::NoStatus) {}
virtual void start();
virtual bool finished() {
@ -120,6 +122,8 @@ public:
return _errorString.isEmpty() ? reply()->errorString() : _errorString;
};
SyncFileItem::Status errorStatus() { return _errorStatus; }
signals:
void finishedSignal();
void downloadProgress(qint64,qint64);