Skip to content

Commit

Permalink
[arcgis rest] Try to retrieve detailed error messages from network re…
Browse files Browse the repository at this point in the history
…plies when an error occurs

When these occur, the http error string is set to a very generic "error
occurred" message, while the reply content contains a user-useful
error explanation in html format. So we do a very simple attempt to parse
the better error message from the reply and if successful, use that
instead of the generic one.
  • Loading branch information
nyalldawson committed Jan 24, 2022
1 parent 0480319 commit 187b498
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/providers/arcgis/qgsarcgisrestquery.cpp
Expand Up @@ -164,6 +164,16 @@ QByteArray QgsArcGisRestQueryUtils::queryService( const QUrl &u, const QString &
QgsDebugMsg( QStringLiteral( "Network error: %1" ).arg( networkRequest.errorMessage() ) );
errorTitle = QStringLiteral( "Network error" );
errorText = networkRequest.errorMessage();

// try to get detailed error message from reply
const QString content = networkRequest.reply().content();
const thread_local QRegularExpression errorRx( QStringLiteral( "Error: <.*?>(.*?)<" ) );
const QRegularExpressionMatch match = errorRx.match( content );
if ( match.hasMatch() )
{
errorText = match.captured( 1 );
}

return QByteArray();
}

Expand Down

0 comments on commit 187b498

Please sign in to comment.