diff --git a/src/apis/subscribe/service.ts b/src/apis/subscribe/service.ts index 00bd63ef..497ac035 100644 --- a/src/apis/subscribe/service.ts +++ b/src/apis/subscribe/service.ts @@ -73,22 +73,23 @@ export const pushNotification = (major: string): Promise => { db.query(query, async (err: Error, res: SubscribeUser[]) => { if (err) console.error(err); - try { - const message: PushMessage = { - title: `${major} 알림`, - body: '새로운 공지가 추가됐어요', - icon: './icons/icon-192x192.png', - }; + const message: PushMessage = { + title: `${major} 알림`, + body: '새로운 공지가 추가됐어요', + icon: './icons/icon-192x192.png', + }; - for (const userInfo of res) { + for (const userInfo of res) { + try { await webpush.sendNotification( JSON.parse(userInfo.user), JSON.stringify(message), ); + } catch (error) { + notificationToSlack(error); } resolve(res.length); - } catch (error) { - notificationToSlack(error); + resolve(0); } });