From 87c9f554155abc2496ef91f1caaa711cbcb99497 Mon Sep 17 00:00:00 2001
From: John Holland <john.holland@nice.org.uk>
Date: Thu, 30 May 2024 17:12:56 +0100
Subject: [PATCH] NXT-348 Added error handling for incorrect itemKey

---
 web/src/pages/api/cache.api.ts | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/web/src/pages/api/cache.api.ts b/web/src/pages/api/cache.api.ts
index 6a6d880ff..6d9416f72 100644
--- a/web/src/pages/api/cache.api.ts
+++ b/web/src/pages/api/cache.api.ts
@@ -2,10 +2,10 @@ import { type NextApiRequest, type NextApiResponse } from "next";
 
 import { cache, getCacheKey } from "@/cache";
 
-export default function handler(
+export default async function handler(
 	req: NextApiRequest,
 	res: NextApiResponse
-): void {
+): Promise<void> {
 	const action = req.query["action"];
 	const expectedGroupKeys = ["publications", "indev"];
 
@@ -22,6 +22,11 @@ export default function handler(
 
 				if (expectedGroupKeys.includes(groupKey)) {
 					try {
+						await cache.get(cacheKey).then((res) => {
+							if (!res) {
+								throw Error(`itemKey param not found in cache: ${itemKey}`);
+							}
+						});
 						cache.del(cacheKey);
 						res.status(200).json({
 							message: `Successfully wiped cache for route: ${cacheKey}`,