fix(helper): fix Helper.installAsyncStackHooks method (#4478)

Using Error.captureStackTrace instead of new Error () to avoid UnhandledPromiseRejectionWarning
This commit is contained in:
Adriel Codeco 2019-05-31 23:39:32 -03:00 committed by Andrey Lushnikov
parent d221c02c13
commit ac611bacac
2 changed files with 4 additions and 2 deletions

View File

@ -28,7 +28,8 @@ class Helper {
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction')
continue;
Reflect.set(classType.prototype, methodName, function(...args) {
const syncStack = new Error();
const syncStack = {};
Error.captureStackTrace(syncStack);
return method.call(this, ...args).catch(e => {
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
const clientStack = stack.substring(stack.indexOf('\n'));

View File

@ -107,7 +107,8 @@ class Helper {
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction')
continue;
Reflect.set(classType.prototype, methodName, function(...args) {
const syncStack = new Error();
const syncStack = {};
Error.captureStackTrace(syncStack);
return method.call(this, ...args).catch(e => {
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
const clientStack = stack.substring(stack.indexOf('\n'));