From 1ecbca40a3d8dd275bdce67353c41b0532c7a15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20J=C3=A4derberg?= Date: Tue, 25 Nov 2025 09:52:45 +0000 Subject: [PATCH] Merged in fix/add-logging-when-cache-get-fails (pull request #3215) fix: add logging when we fail to get cache data * fix: add logging when we fail to get cache data Approved-by: Linus Flood --- .../common/dataCache/DistributedCache/get.ts | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/common/dataCache/DistributedCache/get.ts b/packages/common/dataCache/DistributedCache/get.ts index d0e4457ae..f1f65a8b6 100644 --- a/packages/common/dataCache/DistributedCache/get.ts +++ b/packages/common/dataCache/DistributedCache/get.ts @@ -21,7 +21,10 @@ export async function get(key: string) { }) ) - if (!response || !response.ok || error) { + const isJson = response?.headers + .get("content-type") + ?.includes("application/json") + if (!response || !response.ok || error || !isJson) { if (response?.status === 404) { cacheLogger.debug( `Miss '${key}' took ${(performance.now() - perf).toFixed(2)}ms` @@ -29,11 +32,19 @@ export async function get(key: string) { return undefined } + cacheLogger.error(`Failed to get cache for key ${key}`, { + cacheKey: key, + statusCode: response?.status, + statusText: response?.statusText, + contentType: response?.headers.get("content-type"), + }) + Sentry.captureException(error ?? new Error("Unable to GET cachekey"), { extra: { cacheKey: key, statusCode: response?.status, statusText: response?.statusText, + contentType: response?.headers.get("content-type"), }, }) return undefined @@ -45,8 +56,8 @@ export async function get(key: string) { if (jsonError) { cacheLogger.error("Failed to parse cache response", { - key, - error: jsonError, + cacheKey: key, + error: serializeError(jsonError), }) await deleteKey(key) @@ -59,3 +70,23 @@ export async function get(key: string) { return data?.data } + +function serializeError(error: unknown): + | string + | { + name: string + message: string + stack?: string + cause?: unknown + } { + if (error instanceof Error) { + return { + name: error.name, + message: error.message, + stack: error.stack, + cause: error.cause ? serializeError(error.cause) : undefined, + } + } else { + return String(error) + } +}