Commit 0fe79ae3 authored by Stefano Crocco's avatar Stefano Crocco Committed by David Faure
Browse files

Improve handling of ioslave failures

parent 500b44bd
......@@ -86,9 +86,33 @@ void WebEnginePartKIOHandler::processSlaveOutput()
void WebEnginePartKIOHandler::kioJobFinished(KIO::StoredTransferJob* job)
m_error = job->error() == 0 ? QWebEngineUrlRequestJob::NoError : QWebEngineUrlRequestJob::RequestFailed;
m_errorMessage = isSuccessful() ? job->errorString() : QString();
//Try to get information from the job even in case it reports errors, so that we can avoid using QWebEngineUrlRequestJob::fail.
//The reason is that calling fail displays a generic error message provided by QtWebEngine. Using QWebEngineUrlRequestJob::fail can
//be avoided in two situations:
//- job->errorString() is not empty
//- job->data() is not empty and the mimetype is valid
//In the first case, the error string will be wrapped inside a minimal html page and it'll be used as reply. If the error code is
//KIO::ERR_SLAVE_DEFINED, the string can be rich text: in this case, it won't be wrapped.
//In the second case we use job->data() as reply, even if it may contain incomplete data. The reason is that some ioslaves (for example
//the `man` ioslave, since the d5f2beb2c13c8b3a202b4979027ad5430f007705 commit) report the error message inside job->data() instead of
m_error = QWebEngineUrlRequestJob::NoError;
QMimeDatabase db;
m_mimeType = db.mimeTypeForName(job->mimetype());
m_data = job->data();
m_mimeType = QMimeDatabase().mimeTypeForName(job->mimetype());
if (job->error() != 0) {
m_mimeType = db.mimeTypeForName("text/html");
if (!job->errorString().isEmpty()) {
if (job->error() == KIO::ERR_SLAVE_DEFINED && job->errorString().contains("<html>")) {
m_data = job->errorString().toUtf8();
} else {
QString html = QString("<html><body><h1>Error</h1>%1</body></html>").arg(job->errorString());
m_data = html.toUtf8();
} else if (m_data.isEmpty() || !m_mimeType.isValid()) {
m_error = QWebEngineUrlRequestJob::RequestFailed;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment