From bb5d0c7519e20c521b50cc116a9dec71a43fc706 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Tue, 7 Jan 2025 05:45:02 +0100 Subject: [PATCH] fix: check connection link before searching --- src/controllers/NotionController.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/controllers/NotionController.ts b/src/controllers/NotionController.ts index 60f8ee10..5af26148 100644 --- a/src/controllers/NotionController.ts +++ b/src/controllers/NotionController.ts @@ -37,6 +37,18 @@ class NotionController { async search(req: Request, res: Response) { try { + // Check for Notion connection first + const linkInfo = await this.service.getNotionLinkInfo(res.locals.owner); + if (!linkInfo.isConnected) { + const renewalLink = this.service.getNotionAuthorizationLink( + this.service.getClientId() + ); + return res.status(401).json({ + message: `Notion is not connected. Please connect your account here.`, + }); + } + + // Proceed with search if connected const query = req.body.query.toString() || ''; const result = await this.service.search(query, getOwner(res)); res.json(result);