Skip to content

Commit

Permalink
Merge pull request #9611 from pblottiere/server_log_exceptions
Browse files Browse the repository at this point in the history
[server] log exceptions
  • Loading branch information
pblottiere authored Mar 25, 2019
2 parents 250c626 + b0ef62b commit daf53a1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions python/server/auto_generated/qgsserverexception.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Constructor

virtual QByteArray formatResponse( QString &responseFormat /Out/ ) const;
%Docstring
Format the exception for sending to client
Formats the exception for sending to client


:return: - QByteArray the fermatted response.
:return: - QByteArray The formatted response.
- responseFormat: QString to store the content type of the response format.

The defaolt implementation return text/xml format.
The default implementation returns text/xml format.
%End

};
Expand Down
5 changes: 4 additions & 1 deletion src/server/qgsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,14 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
catch ( QgsServerException &ex )
{
responseDecorator.write( ex );
QString format;
QgsMessageLog::logMessage( ex.formatResponse( format ), QStringLiteral( "Server" ), Qgis::Info );
}
catch ( QgsException &ex )
{
// Internal server error
response.sendError( 500, ex.what() );
response.sendError( 500, QStringLiteral( "Internal Server Error" ) );
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::Critical );
}
}
// Terminate the response
Expand Down
6 changes: 3 additions & 3 deletions src/server/qgsserverexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class SERVER_EXPORT QgsServerException
int responseCode() const { return mResponseCode; }

/**
* Format the exception for sending to client
* Formats the exception for sending to client
*
* \param responseFormat QString to store the content type of the response format.
* \returns QByteArray the fermatted response.
* \returns QByteArray The formatted response.
*
* The defaolt implementation return text/xml format.
* The default implementation returns text/xml format.
*/
virtual QByteArray formatResponse( QString &responseFormat SIP_OUT ) const;

Expand Down
5 changes: 0 additions & 5 deletions src/server/qgsserverresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ void QgsServerResponse::write( const QString &data )
QIODevice *iodev = io();
if ( iodev )
{
//QTextStream stream( iodev );
//stream << data;
iodev->write( data.toUtf8() );
}
else
Expand All @@ -37,7 +35,6 @@ void QgsServerResponse::write( const QString &data )
}
}


qint64 QgsServerResponse::write( const QByteArray &byteArray )
{
QIODevice *iodev = io();
Expand All @@ -48,7 +45,6 @@ qint64 QgsServerResponse::write( const QByteArray &byteArray )
return 0;
}


qint64 QgsServerResponse::write( const char *data, qint64 maxsize )
{
QIODevice *iodev = io();
Expand Down Expand Up @@ -85,4 +81,3 @@ void QgsServerResponse::write( const QgsServerException &ex )
setHeader( "Content-Type", responseFormat );
write( ba );
}

0 comments on commit daf53a1

Please sign in to comment.