79
80 const devMode = process.env.NODE_ENV === 'development';
81
82 if (!devMode && (!tokenValue || !verifyToken(tokenValue))) { 83 res.status(401).json({ error: 'Unauthorized' }).end();
84 }
85
43
44const sendMail = async (mails: MeetingEmail[]) => {
45 try {
46 mails.forEach(async (email) => { 47 await axios.post('/api/email/schedule/', { 48 email, 49 }); 50 }); 51 } catch (err) {
52 toast.custom(<Error error="Error sending emails" />);
53 }
Using promises is forbidden in places where the TypeScript compiler allows them but they are not handled properly. These situations can often arise due to a missing await keyword or just a misunderstanding of the way async functions are handled/awaited.
const promise = Promise.resolve('value');
if (promise) {
// Do something
}
const val = promise ? 123 : 456;
while (promise) {
// Do something
}
const promise = Promise.resolve('value');
if (await promise) {
// Do something
}
const val = (await promise) ? 123 : 456;
while (await promise) {
// Do something
}
for (const value of [1, 2, 3]) {
await doSomething(value);
}
new Promise((resolve, reject) => {
// Do something
resolve();
});
const eventEmitter = new EventEmitter();
eventEmitter.on('some-event', () => {
doSomething();
});