QGIS/python/server/server.sip.in
Alessandro Pasotti 4cc7a0ffa6 Server: catch Python exceptions from plugins
Make sure Python exceptions are converted into
QgsServerException and catched by the main
service executor.

Without this patch, the server process is terminated
(aborted).
2019-08-19 18:32:03 +02:00

44 lines
1.1 KiB
Plaintext

%Module(name=qgis._server,
keyword_arguments="All")
${DEFAULTDOCSTRINGSIGNATURE}
%Import QtCore/QtCoremod.sip
%Import QtGui/QtGuimod.sip
%Import QtXml/QtXmlmod.sip
%Import core/core.sip
%Include qgsserverexception.sip
%Feature HAVE_SERVER_PYTHON_PLUGINS
%Include server_auto.sip
%VirtualErrorHandler serverapi_badrequest_exception_handler
PyObject *exception, *value, *traceback;
PyErr_Fetch(&exception, &value, &traceback);
SIP_RELEASE_GIL( sipGILState );
QString strVal = "API bad request error";
if ( value && PyUnicode_Check(value) )
{
Py_ssize_t size;
strVal = QString::fromUtf8( PyUnicode_AsUTF8AndSize(value, &size) );
}
throw QgsServerApiBadRequestException( strVal );
%End
%VirtualErrorHandler server_exception_handler
PyObject *exception, *value, *traceback;
PyErr_Fetch(&exception, &value, &traceback);
SIP_RELEASE_GIL( sipGILState );
QString strVal = "Server internal error";
if ( value && PyUnicode_Check(value) )
{
Py_ssize_t size;
strVal = QString::fromUtf8( PyUnicode_AsUTF8AndSize(value, &size) );
}
throw QgsServerException( strVal );
%End