Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip HTML when receiving HTML server errors in cloud API #5115

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/core/qfieldcloudconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QNetworkCookie>
#include <QNetworkCookieJar>
#include <QSettings>
#include <QTextDocument>
#include <QTextDocumentFragment>
#include <QTimer>
#include <QUrlQuery>
#include <qgsapplication.h>
Expand Down Expand Up @@ -507,29 +507,31 @@ QFieldCloudConnection::CloudError::CloudError( QNetworkReply *reply )
break;
}

errorMessage = QTextDocumentFragment::fromHtml( errorMessage ).toPlainText().trimmed();

QString httpErrorMessage = QStringLiteral( "[HTTP/%1] %2 " ).arg( mHttpCode ).arg( reply->url().toString() );
httpErrorMessage += ( mHttpCode >= 400 )
? tr( "Server Error." )
: tr( "Network Error." );
httpErrorMessage += mPayload.left( 200 );
httpErrorMessage = QTextDocumentFragment::fromHtml( httpErrorMessage ).toPlainText().trimmed();
QString payloadPlainText = QTextDocumentFragment::fromHtml( mPayload ).toPlainText().trimmed();

if ( mPayload.size() > 200 )
errorMessage += QStringLiteral( "…" );

if ( errorMessage.isEmpty() )
{
errorMessage = httpErrorMessage;
QgsMessageLog::logMessage( QStringLiteral( "%1\n%2\n%3" ).arg( errorMessage, mPayload ).arg( reply->errorString() ) );
QgsMessageLog::logMessage( QStringLiteral( "%1\n%2\n%3" ).arg( errorMessage, payloadPlainText ).arg( reply->errorString() ) );
}
else
{
QgsMessageLog::logMessage( QStringLiteral( "%1\n%2\n%3\n%4" ).arg( errorMessage, httpErrorMessage, mPayload ).arg( reply->errorString() ) );
QgsMessageLog::logMessage( QStringLiteral( "%1\n%2\n%3\n%4" ).arg( errorMessage, httpErrorMessage, payloadPlainText ).arg( reply->errorString() ) );
}

// strip HTML tags
QTextDocument doc;
doc.setHtml( errorMessage );
errorMessage = doc.toPlainText();
suricactus marked this conversation as resolved.
Show resolved Hide resolved
errorMessage = QTextDocumentFragment::fromHtml( httpErrorMessage ).toPlainText();

mMessage = errorMessage;
}
Expand Down
Loading