From 023f34c292fcfed4b84d3036dfe6e4ceef08e0c1 Mon Sep 17 00:00:00 2001 From: devfle <52854338+devfle@users.noreply.github.com> Date: Sun, 11 Feb 2024 14:51:28 +0100 Subject: [PATCH] refactor: improve error handling --- src/index.ts | 5 ++--- src/utils.ts | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 69f4b17..60134ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ if (!shopList) { errorMsg( "NO SHOP DATA FOUND IN 'shop-list.json' YOU HAVE TO CREATE AND CONFIGURE IT.", ); - process.exit(1); + throw new TypeError(); } /** @@ -66,8 +66,7 @@ setInterval( const fetchedTextDom = await fetchWebsiteData(productEndpoint); if (!fetchedTextDom) { - errorMsg('FETCH DATA IS NOT VALID'); - return; + return errorMsg('FETCH DATA IS NOT VALID'); } const searchResult = searchInDom(fetchedTextDom, searchQuery); diff --git a/src/utils.ts b/src/utils.ts index b860ccb..e712918 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -69,14 +69,13 @@ const infoMsg = (message: string) => { const sendNotification = (client: Client, message: string = '') => { if (!process.env.CHANNEL_ID) { errorMsg('NO CHANNEL ID WAS FOUND'); - return; + throw new TypeError(); } const channel = client.channels.cache.get(process.env.CHANNEL_ID); if (!channel) { - errorMsg('CHANNEL WITH THE GIVEN ID WAS NOT FOUND'); - return; + return warnMsg('CHANNEL WITH THE GIVEN ID WAS NOT FOUND'); } (channel as TextChannel).send(message);