async function getUser(id: string) {
try {
return await repo.findById(id);
} catch {
return null;
}
}
It swallows every error, so a database outage looks the same as a missing user
The code catches every error and returns null, so it hides real failures. If the database is down, callers think the user is missing. They may answer 404 or create a duplicate user. Also, nothing is logged, so nobody sees the outage.
"The catch block needs an (err) parameter to compile" is wrong. A catch without (err) is called optional catch binding, and it is valid modern JavaScript.
Read more