From cdb9243d254013d07aef166dc96f98cccfed2187 Mon Sep 17 00:00:00 2001 From: Dhenain Ambroise Date: Fri, 25 Jun 2021 10:20:55 +0200 Subject: [PATCH] Add missing await/flush in API endpoints --- src/modules/core/i18n/middlewares/localeMiddleware.ts | 2 +- src/pages/api/startVercelDeployment.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/core/i18n/middlewares/localeMiddleware.ts b/src/modules/core/i18n/middlewares/localeMiddleware.ts index b2bb06a6..eeda88e8 100644 --- a/src/modules/core/i18n/middlewares/localeMiddleware.ts +++ b/src/modules/core/i18n/middlewares/localeMiddleware.ts @@ -65,7 +65,7 @@ export const localeMiddleware = async (req: NextApiRequest, res: NextApiResponse localeFound = customer?.availableLanguages?.[0] || DEFAULT_LOCALE; } - logEvent(AMPLITUDE_EVENTS.API_LOCALE_MIDDLEWARE_INVOKED, null, { + await logEvent(AMPLITUDE_EVENTS.API_LOCALE_MIDDLEWARE_INVOKED, null, { locale: localeFound, }); diff --git a/src/pages/api/startVercelDeployment.ts b/src/pages/api/startVercelDeployment.ts index 2d534744..ad2a0d54 100644 --- a/src/pages/api/startVercelDeployment.ts +++ b/src/pages/api/startVercelDeployment.ts @@ -8,6 +8,7 @@ import dispatchWorkflowByPath from '@/modules/core/githubActions/dispatchWorkflo import { createLogger } from '@/modules/core/logging/logger'; import { ALERT_TYPES } from '@/modules/core/sentry/config'; import { configureReq } from '@/modules/core/sentry/server'; +import { flushSafe } from '@/modules/core/sentry/universal'; import * as Sentry from '@sentry/node'; import size from 'lodash.size'; import { @@ -141,6 +142,8 @@ const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse) Sentry.captureException(new Error(errorMessage)); logger.error(errorMessage); + await flushSafe(); + return redirect(res, redirectTo, statusCode); } @@ -159,6 +162,8 @@ const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse) Sentry.captureException(new Error(errorMessage)); logger.error(errorMessage); + await flushSafe(); + return redirect(res, redirectTo, statusCode); } @@ -167,6 +172,8 @@ const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse) Sentry.captureException(new Error(errorMessage)); logger.error(errorMessage); + await flushSafe(); + return redirect(res, redirectTo, statusCode); } @@ -179,6 +186,8 @@ const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse) Sentry.captureException(e); logger.error(e.message); + await flushSafe(); + res.json({ error: true, message: process.env.NEXT_PUBLIC_APP_STAGE === 'production' ? undefined : e.message,