Web: handle system exit exceptions

This commit is contained in:
wmayer
2021-10-14 15:46:37 +02:00
parent cea1216ea2
commit 539bd3ceb1
2 changed files with 22 additions and 13 deletions

View File

@@ -29,6 +29,7 @@
#endif
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Base/PyObjectBase.h>
#include <CXX/Extensions.hxx>
@@ -129,21 +130,26 @@ private:
throw Py::OverflowError("port number is lower than 0");
}
AppServer server(true);
if (server.listen(QHostAddress(QString::fromLatin1(addr)), port)) {
bool ok = server.waitForNewConnection(timeout);
QTcpSocket* socket = server.nextPendingConnection();
if (socket) {
socket->waitForReadyRead();
}
try {
AppServer server(true);
if (server.listen(QHostAddress(QString::fromLatin1(addr)), port)) {
bool ok = server.waitForNewConnection(timeout);
QTcpSocket* socket = server.nextPendingConnection();
if (socket) {
socket->waitForReadyRead();
}
server.close();
return Py::Boolean(ok);
server.close();
return Py::Boolean(ok);
}
else {
std::stringstream out;
out << "Server failed to listen at address " << addr << " and port " << port;
throw Py::RuntimeError(out.str());
}
}
else {
std::stringstream out;
out << "Server failed to listen at address " << addr << " and port " << port;
throw Py::RuntimeError(out.str());
catch (const Base::SystemExitException& e) {
throw Py::RuntimeError(e.what());
}
}

View File

@@ -216,6 +216,9 @@ std::string AppServer::runPython(const QByteArray& msg)
str += "\n\n";
str += e.getStackTrace();
}
catch (Base::SystemExitException &) {
throw;
}
catch (Base::Exception &e) {
str = e.what();
}