Add error handling to node_helper startup sequence (#2945)

Fixes https://github.com/MichMich/MagicMirror/issues/2944

Also splits the Server js into a constrcutor and an open call to remove
one callback parameter :-)

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck
2022-10-19 21:40:43 +02:00
committed by GitHub
parent 7bd944391e
commit 64ed5a54cb
3 changed files with 130 additions and 117 deletions

View File

@@ -223,24 +223,35 @@ function App() {
}
loadModules(modules, function () {
httpServer = new Server(config, function (app, io) {
Log.log("Server started ...");
httpServer = new Server(config);
const { app, io } = httpServer.open();
Log.log("Server started ...");
const nodePromises = [];
const nodePromises = [];
for (let nodeHelper of nodeHelpers) {
nodeHelper.setExpressApp(app);
nodeHelper.setSocketIO(io);
for (let nodeHelper of nodeHelpers) {
nodeHelper.setExpressApp(app);
nodeHelper.setSocketIO(io);
try {
nodePromises.push(nodeHelper.start());
} catch (error) {
Log.error(`Error when starting node_helper for module ${nodeHelper.name}:`);
Log.error(error);
}
}
Promise.allSettled(nodePromises).then(() => {
Log.log("Sockets connected & modules started ...");
if (typeof callback === "function") {
callback(config);
Promise.allSettled(nodePromises).then((results) => {
// Log errors that happened during async node_helper startup
results.forEach((result) => {
if (result.status === "rejected") {
Log.error(result.reason);
}
});
Log.log("Sockets connected & modules started ...");
if (typeof callback === "function") {
callback(config);
}
});
});
});