Add error handling to group parsing in chat search

8ef49b40b230a50b70a92d1eee245f76978efbb9

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +4 -0Showing whitespace changes
src/endpoints/chats.js+4 -0
@@ -561,11 +561,15 @@ router.post('/search', jsonParser, function (request, response) {
561561
562 let targetGroup;562 let targetGroup;
563 for (const groupFile of groupFiles) {563 for (const groupFile of groupFiles) {
564 try {
564 const groupData = JSON.parse(fs.readFileSync(path.join(groupDir, groupFile), 'utf8'));565 const groupData = JSON.parse(fs.readFileSync(path.join(groupDir, groupFile), 'utf8'));
565 if (groupData.id === group_id) {566 if (groupData.id === group_id) {
566 targetGroup = groupData;567 targetGroup = groupData;
567 break;568 break;
568 }569 }
570 } catch (error) {
571 console.error(groupFile, 'group file is corrupted:', error);
572 }
569 }573 }
570574
571 if (!targetGroup?.chats) {575 if (!targetGroup?.chats) {