What is the best practice for handling errors in JavaScript?
I have a errorMan function which takes care of errors and prevents my NodeJS app from breaking. Where should I use this function to catch errors?
Scenario #1
async function helperFunc() {
try {
// Do some async requests
} catch (error) {
// returns false
errorMan({error, path:__filename, name:"helperFunc"});
}
}
async function bar() {
const get = await helperFunc();
if(!get) return;
}
Scenario #2
async function helperFunc() {
// Do some async requests and return
}
async function bar() {
try {
const get = await helperFunc();
} catch (error) {
// Can't get real path and exact function name
errorMan({error, path:__filename, name:"?"});
}
}