diff --git a/src/lib/types.ts b/src/lib/types.ts index 6699d1cea..5691752da 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -58,6 +58,7 @@ export interface EmailEsrfApiRequestBody { } export interface HealthApiResponse { + adobeAnalyticsScriptSrc: string | null appBaseUri: string | null buildDate: string | null environment: string | null diff --git a/src/pages/api/alerts.ts b/src/pages/api/alerts.ts index ec154e697..f85aba4c4 100644 --- a/src/pages/api/alerts.ts +++ b/src/pages/api/alerts.ts @@ -10,18 +10,19 @@ export default async function handler( res: NextApiResponse, ) { try { - if (!process.env.ALERT_JSON_URI) { - logger.error('ALERT_JSON_URI must not be undefined, null or empty') - throw Error( - 'process.env.ALERT_JSON_URI must not be undefined, null or empty', - ) - } - if (req.method !== 'GET') { logger.debug(`error 405: Invalid request method ${req.method}`) return res.status(405).send(`Invalid request method ${req.method}`) } + if (!process.env.ALERT_JSON_URI?.trim()) { + logger.warn( + 'ALERT_JSON_URI is either undefined, null, or an empty string. Consequently, an empty array is being returned.', + ) + res.status(200).json([]) + return + } + const query = req.query const { page } = query @@ -52,10 +53,10 @@ export default async function handler( type: alert.type, })) - return res.status(200).json(alerts) + res.status(200).json(alerts) } catch (error) { // If there's a problem with the alerts, we return 500 but with an empty list logger.error(error, 'Failed to fetch alerts') - return res.status(500).json([]) + res.status(500).json([]) } } diff --git a/src/pages/api/health.ts b/src/pages/api/health.ts index 7cb8b2da3..a1a98b47c 100644 --- a/src/pages/api/health.ts +++ b/src/pages/api/health.ts @@ -16,6 +16,7 @@ export default async function handler( } res.status(200).json({ + adobeAnalyticsScriptSrc: process.env.ADOBE_ANALYTICS_SCRIPT_SRC ?? null, appBaseUri: process.env.APP_BASE_URI ?? null, buildDate: process.env.NEXT_PUBLIC_BUILD_DATE ?? null, environment: process.env.ENVIRONMENT ?? null,