Skip to content

Commit

Permalink
refactor: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
devfle committed Feb 11, 2024
1 parent 4b60b89 commit 023f34c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 023f34c

Please sign in to comment.