%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