From fffcb060ac6f4d3166965d51c982bd466071e884 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sat, 9 Apr 2022 10:55:45 -0500 Subject: [PATCH] =?UTF-8?q?fix(webhook):=20=F0=9F=90=9B=20Graceful=20fail?= =?UTF-8?q?=20if=20typebot=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blocks/[blockId]/steps/[stepId]/executeWebhook.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/executeWebhook.ts b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/executeWebhook.ts index 8cbca6663..386ca4f24 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/executeWebhook.ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/steps/[stepId]/executeWebhook.ts @@ -15,7 +15,13 @@ import { import { parseVariables } from 'bot-engine' import { NextApiRequest, NextApiResponse } from 'next' import got, { Method, Headers, HTTPError } from 'got' -import { byId, initMiddleware, methodNotAllowed, parseAnswers } from 'utils' +import { + byId, + initMiddleware, + methodNotAllowed, + notFound, + parseAnswers, +} from 'utils' import { stringify } from 'qs' import { withSentry } from '@sentry/nextjs' import Cors from 'cors' @@ -37,7 +43,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const typebot = (await prisma.typebot.findUnique({ where: { id: typebotId }, include: { webhooks: true }, - })) as unknown as Typebot & { webhooks: Webhook[] } + })) as unknown as (Typebot & { webhooks: Webhook[] }) | null + if (!typebot) return notFound(res) const step = typebot.blocks .find(byId(blockId)) ?.steps.find(byId(stepId)) as WebhookStep