From 592b5e49b6c1f87ab70302c4f23e7ffd9c53fbd4 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 19 Nov 2017 23:49:27 -0800 Subject: [PATCH] Added no results text for Slack slash command --- server/api/hooks.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/server/api/hooks.js b/server/api/hooks.js index 999c579d..26269a00 100644 --- a/server/api/hooks.js +++ b/server/api/hooks.js @@ -26,24 +26,30 @@ router.post('hooks.slack', async ctx => { limit: 5, }); - const results = []; - let number = 1; - for (const document of documents) { - results.push( - `${number}. <${process.env.URL}${document.getUrl()}|${document.title}>` - ); - number += 1; - } + if (documents) { + const results = []; + let number = 1; + for (const document of documents) { + results.push( + `${number}. <${process.env.URL}${document.getUrl()}|${document.title}>` + ); + number += 1; + } - ctx.body = { - text: 'Search results:', - attachments: [ - { - text: results.join('\n'), - color: '#3AA3E3', - }, - ], - }; + ctx.body = { + text: 'Search results:', + attachments: [ + { + text: results.join('\n'), + color: '#3AA3E3', + }, + ], + }; + } else { + ctx.body = { + text: 'No search results', + }; + } }); export default router;