Add error handling to group parsing in chat search

8ef49b40b230a50b70a92d1eee245f76978efbb9

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

1 files changed, +8 -4Ignore whitespace
src/endpoints/chats.js+8 -4
@@ -561,10 +561,14 @@ router.post('/search', jsonParser, function (request, response) {
561561
562562 let targetGroup;
563563 for (const groupFile of groupFiles) {
564- const groupData = JSON.parse(fs.readFileSync(path.join(groupDir, groupFile), 'utf8'));
564+ try {
565- if (groupData.id === group_id) {
565+ const groupData = JSON.parse(fs.readFileSync(path.join(groupDir, groupFile), 'utf8'));
566- targetGroup = groupData;
566+ if (groupData.id === group_id) {
567- break;
567+ targetGroup = groupData;
568+ break;
569+ }
570+ } catch (error) {
571+ console.error(groupFile, 'group file is corrupted:', error);
568572 }
569573 }
570574