Add fallback when logging uncaughtExceptions

This commit is contained in:
Nick O'Leary 2021-10-06 17:33:04 +01:00
parent bd142a9710
commit 273d9c76a7
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 12 additions and 4 deletions

View File

@ -234,11 +234,11 @@ httpsPromise.then(function(startupHttps) {
// Get the result of the function, because createServer doesn't accept functions as input
Promise.resolve(settings.https()).then(function(refreshedHttps) {
if (refreshedHttps) {
// The key/cert needs to be updated in the NodeJs http(s) server, when no key/cert is yet available or when the key/cert has changed.
// The key/cert needs to be updated in the NodeJs http(s) server, when no key/cert is yet available or when the key/cert has changed.
// Note that the refreshed key/cert can be supplied as a string or a buffer.
var updateKey = (server.key == undefined || (Buffer.isBuffer(server.key) && !server.key.equals(refreshedHttps.key)) || (typeof server.key == "string" && server.key != refreshedHttps.key));
var updateCert = (server.cert == undefined || (Buffer.isBuffer(server.cert) && !server.cert.equals(refreshedHttps.cert)) || (typeof server.cert == "string" && server.cert != refreshedHttps.cert));
// Only update the credentials in the server when key or cert has changed
if(updateKey || updateCert) {
server.setSecureContext(refreshedHttps);
@ -455,9 +455,17 @@ httpsPromise.then(function(startupHttps) {
process.on('uncaughtException',function(err) {
util.log('[red] Uncaught Exception:');
if (err.stack) {
RED.log.error(err.stack);
try {
RED.log.error(err.stack);
} catch(err2) {
util.log(err.stack);
}
} else {
RED.log.error(err);
try {
RED.log.error(err);
} catch(err2) {
util.log(err);
}
}
process.exit(1);
});