1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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

View File

@ -234,11 +234,11 @@ httpsPromise.then(function(startupHttps) {
// Get the result of the function, because createServer doesn't accept functions as input // Get the result of the function, because createServer doesn't accept functions as input
Promise.resolve(settings.https()).then(function(refreshedHttps) { Promise.resolve(settings.https()).then(function(refreshedHttps) {
if (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. // 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 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)); 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 // Only update the credentials in the server when key or cert has changed
if(updateKey || updateCert) { if(updateKey || updateCert) {
server.setSecureContext(refreshedHttps); server.setSecureContext(refreshedHttps);
@ -455,9 +455,17 @@ httpsPromise.then(function(startupHttps) {
process.on('uncaughtException',function(err) { process.on('uncaughtException',function(err) {
util.log('[red] Uncaught Exception:'); util.log('[red] Uncaught Exception:');
if (err.stack) { if (err.stack) {
RED.log.error(err.stack); try {
RED.log.error(err.stack);
} catch(err2) {
util.log(err.stack);
}
} else { } else {
RED.log.error(err); try {
RED.log.error(err);
} catch(err2) {
util.log(err);
}
} }
process.exit(1); process.exit(1);
}); });