fix:return 404 if resource not found

This commit is contained in:
yifang 2022-01-08 12:22:41 +08:00
parent 4d648aca09
commit c74b0bc6cf
2 changed files with 16 additions and 7 deletions

View file

@ -520,8 +520,10 @@ void ArticleResourceReply::readyReadSlot()
void ArticleResourceReply::finishedSlot()
{
if ( req->dataSize() < 0 )
errorOccurred( ContentNotFoundError );
if (req->dataSize() < 0) {
emit error(ContentNotFoundError);
setError(ContentNotFoundError, "content not found");
}
emit finished();
}

View file

@ -10,10 +10,17 @@ void GicoSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QNetworkRequest request;
request.setUrl( url );
QNetworkReply* reply=this->mManager.createRequest(QNetworkAccessManager::GetOperation,request,NULL);
QNetworkReply *reply = this->mManager.createRequest(QNetworkAccessManager::GetOperation, request, NULL);
QMimeType mineType=db.mimeTypeForUrl (url);
QString contentType=mineType.name ();
// Reply segment
requestJob->reply(contentType.toLatin1(), reply);
connect(reply, &QNetworkReply::finished, requestJob, [=]() {
if (reply->error() == QNetworkReply::ContentNotFoundError) {
requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound);
return;
}
QMimeType mineType = db.mimeTypeForUrl(url);
QString contentType = mineType.name();
// Reply segment
requestJob->reply(contentType.toLatin1(), reply);
});
}