Skip to content

Commit

Permalink
Log exceptions according Info or Critical errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 22, 2019
1 parent 6028b70 commit eb72f16
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/server/qgsserver.cpp
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/server/qgsserverexception.cpp
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/server/qgsserverexception.h
Expand Up @@ -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;
};
Expand Down
3 changes: 0 additions & 3 deletions src/server/qgsserverresponse.cpp
Expand Up @@ -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 );
}

0 comments on commit eb72f16

Please sign in to comment.