export async function addCapturedResponse(request: Request, response: Response): Promise<void> {
try {
const cacheResponse = await getCachableResponse(request, response);
const filePath = cacheResponse.hash.file; // e.g. "www.carolina.com/6dbb7f0d.json"
captured.set(filePath, {
contentType: cacheResponse.data.contentType ?? "unknown",
content: cacheResponse.data.content ?? "",
url: request.url,
method: request.method,
timestamp: Date.now(),
});
const normalized = stripDynamicParams(request.url);
console.log(
`[ResponseAggregate] Captured ${request.method} ${request.url} → ${filePath} (${captured.size} total)`,
);
console.log(
`[ResponseAggregate] normalized: ${request.method}:${normalized}`,
);
} catch (err) {
console.error("[ResponseAggregate] FAILED to capture:", request.method, request.url);
console.error("[ResponseAggregate] error:", err);
}
}
Capture a request/response pair and store it keyed by
{hostname}/{hash}.json. Uses the same serialization as the MSW mock handler expects:{ contentType, content }.