From 27e1355a8c4c7e7132fb075def8874c76a1693be Mon Sep 17 00:00:00 2001
From: youkunhuang 错误堆栈${errStr}
错误堆栈
', - '',
- errStr,
- '
',
- ].join('');
-
-
setImmediate(function() {
require('util/mail/mail.js').SendMail(key, 'js', 600, {
'Title': key,
@@ -51,65 +46,29 @@ process.on('warning', function(warning) {
'Content': Content
});
});
-
});
-process.on('unhandledRejection', (reason = {}, p = {}) => {
- let errStr = String(reason.stack),
- mod_act,
- module,
- REQUEST;
-
- const key = String(reason.message);
-
- if (p && p.domain && p.domain.currentContext) {
- mod_act = p.domain.currentContext.mod_act;
- module = p.domain.currentContext.module;
- REQUEST = p.domain.currentContext.window.request.REQUEST;
- }
-
- if (errStr === 'undefined') {
-
- const reasonStr = JSON.stringify(reason);
-
- logger.error('unhandledRejection reason: ' + reasonStr);
-
- if (reasonStr === '{}') {
- return;
- }
-
- errStr = reasonStr;
- }
-
- logger.error(errStr);
-
- let Content = [
- '错误堆栈
', - '',
- errStr,
- '
',
- ].join('');
-
- if (mod_act) {
- Content += `mod_act: ${mod_act}
`; - } - if (module) { - Content += `module: ${module}
`; - } - if (REQUEST) { - Content += `url: ${REQUEST.protocol}://${REQUEST.hostname}${REQUEST.href}
`; - } - - if (serverOS.isWindows) { - // return; +process.on('unhandledRejection', (errorOrReason, currPromise) => { + const errStr = String(errorOrReason && errorOrReason.stack || JSON.stringify(errorOrReason)); + const key = String(errorOrReason && errorOrReason.message); + const Content = `错误堆栈
${errStr}
`;
+
+ // 恢复上下文
+ if (currPromise && currPromise.domain) {
+ currPromise.domain.run(function() {
+ logger.error(`unhandledRejection reason: ${errStr}`);
+ setImmediate(function() {
+ require('util/mail/mail.js').SendMail(key, 'js', 600, {
+ 'Title': key,
+ 'runtimeType': 'warning',
+ 'Content': Content
+ });
+ });
+ });
+ } else {
+ logger.error(`unhandledRejection reason: ${errStr}`);
}
-
- require('util/mail/mail.js').SendMail(key, 'js', 600, {
- 'Title': key,
- 'runtimeType': 'unhandledRejection',
- 'Content': Content
- });
});
process.noProcessWarnings = true;