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) + } +}