How to find the caller function details inside the promise function
I have referred and implemented the below functionality
How do you find out the caller function in JavaScript?
(async function() {
try {
let theFunction = () => {
return new Promise(async (resolve, reject) => {
try {
let CallerDetails = theFunction.caller;
console.log(CallerDetails);//I cannot fetch the caller details getting error
resolve("Success")
} catch (error) {
console.error(error);
reject("Something went wrong");
}
});
}
let theOtherFunction = () => {
return new Promise(async (resolve, reject) => {
try {
let Res = await theFunction();
resolve(Res);
} catch (error) {
console.error(error);
reject("Something went wrong");
}
});
}
let Res = await theOtherFunction();
console.log(Res);
} catch (err) {
console.error(err);
}
}());
I am getting below exception
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
at Promise (evalmachine.<anonymous>:6:43)
at new Promise (<anonymous>)
at theFunction (evalmachine.<anonymous>:4:14)
at evalmachine.<anonymous>:27:21
at evalmachine.<anonymous>:33:2
at Script.runInContext (vm.js:133:20)
at Object.runInContext (vm.js:311:6)
at evaluate (/run_dir/repl.js:133:14)
at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
at ReadStream.emit (events.js:198:13)
Something went wrong
In my realtime application, I am having error handling common function which is been called in the catch block of more than 200 functions. I am getting an error in common error handling function but not able to locate from where an error has occurred. So for this purpose, I need the caller function.
But in my stack trace, I am getting the dependency(inside node modules) stack and line number are coming. I am unable to locate the actual function. that's why my only hope to rely on knowing the caller function or to add logs on every function which is calling the error handling function