Log exceptions according Info or Critical errors

This commit is contained in:
Blottiere Paul 2019-03-22 12:32:32 +00:00
parent 6028b70f20
commit eb72f16580
4 changed files with 11 additions and 4 deletions

View File

@ -347,11 +347,13 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
catch ( QgsServerException &ex )
{
responseDecorator.write( ex );
QgsMessageLog::logMessage( ex.formatResponse(), QStringLiteral( "Server" ), Qgis::Info );
}
catch ( QgsException &ex )
{
// Internal server error
response.sendError( 500, ex.what() );
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::Critical );
}
}
// Terminate the response

View File

@ -27,6 +27,12 @@ QgsServerException::QgsServerException( const QString &message, int responseCode
}
QByteArray QgsServerException::formatResponse() const
{
QString responseFormat;
return formatResponse( responseFormat );
}
QByteArray QgsServerException::formatResponse( QString &responseFormat ) const
{
QDomDocument doc;

View File

@ -54,10 +54,12 @@ class SERVER_EXPORT QgsServerException
* \param responseFormat QString to store the content type of the response format.
* \returns QByteArray the fermatted response.
*
* The defaolt implementation return text/xml format.
* The default implementation returns text/xml format.
*/
virtual QByteArray formatResponse( QString &responseFormat SIP_OUT ) const;
QByteArray formatResponse() const;
private:
int mResponseCode;
};

View File

@ -80,7 +80,4 @@ void QgsServerResponse::write( const QgsServerException &ex )
setStatusCode( ex.responseCode() );
setHeader( "Content-Type", responseFormat );
write( ba );
// log exception on server side too
QgsMessageLog::logMessage( ba, QStringLiteral( "Server" ), Qgis::Critical );
}