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
This commit is contained in:
Joakim Jäderberg
2025-11-25 09:52:45 +00:00
parent 2ae3fcb609
commit 1ecbca40a3

View File

@@ -21,7 +21,10 @@ export async function get<T>(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<T>(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<T>(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<T>(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)
}
}