zahmis 5 лет назад
Родитель
Сommit
017efc8c7d
1 измененных файлов с 40 добавлено и 3 удалено
  1. 40 3
      src/server/service/bolt.js

+ 40 - 3
src/server/service/bolt.js

@@ -87,16 +87,33 @@ class BoltService {
       const secondArg = inputSlack[1];
       const secondArg = inputSlack[1];
 
 
       let resultPaths;
       let resultPaths;
-      if (firstArg === 'search') {
+
+      if (firstArg === 'search' && secondArg != null) {
         const { searchService } = this.crowi;
         const { searchService } = this.crowi;
         const option = { limit: 10 };
         const option = { limit: 10 };
         const searchResults = await searchService.searchKeyword(secondArg, null, {}, option);
         const searchResults = await searchService.searchKeyword(secondArg, null, {}, option);
+
+        if (searchResults.data.length === 0) {
+          return this.client.chat.postEphemeral({
+            channel: command.channel_id,
+            user: command.user_id,
+            blocks: [
+              {
+                type: 'section',
+                text: {
+                  type: 'mrkdwn',
+                  text: '*キーワードに該当するページは存在しません。*',
+                },
+              },
+            ],
+          });
+        }
+
         resultPaths = searchResults.data.map((data) => {
         resultPaths = searchResults.data.map((data) => {
           return data._source.path;
           return data._source.path;
         });
         });
       }
       }
 
 
-      // TODO impl try-catch
       try {
       try {
         await this.client.chat.postEphemeral({
         await this.client.chat.postEphemeral({
           channel: command.channel_id,
           channel: command.channel_id,
@@ -120,7 +137,27 @@ class BoltService {
         });
         });
       }
       }
       catch {
       catch {
-        console.log('This is error');
+        logger.error('Failed to get search results.');
+        await this.client.chat.postEphemeral({
+          channel: command.channel_id,
+          user: command.user_id,
+          blocks: [
+            {
+              type: 'section',
+              text: {
+                type: 'mrkdwn',
+                text: '*検索に失敗しました。*',
+              },
+            },
+            {
+              type: 'section',
+              text: {
+                type: 'mrkdwn',
+                text: 'Hint\n /growi search [keyword]',
+              },
+            },
+          ],
+        });
       }
       }
     });
     });
   }
   }