Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[arcgis rest] Try to retrieve detailed error messages from network re…
…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 20, 2022
1 parent 3620c99 commit 7c4a6de
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/providers/arcgis/qgsarcgisrestquery.cpp
Expand Up @@ -161,6 +161,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 7c4a6de

Please sign in to comment.