ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...
    • 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 }.

      Parameters

      • request: Request

        The original Request object

      • response: Response

        A cloned Response (body must not be consumed)

      Returns Promise<void>

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