Spot the bug in the version cache

from API versioning
Node 24 intermediate 4 min 1 issue to find

Find the version isolation bug in this generated cache wrapper.

JavaScript
function serve(headers, cache) {
  const version = headers["x-api-version"] || "v1";
  const key = "/orders/ord-7";
  if (cache.has(key)) return cache.get(key);

  const body = version === "v1"
    ? { id: "ord-7", total: 25.99 }
    : { id: "ord-7", total: { amount: "25.99", currency: "USD" } };
  cache.set(key, body);
  return body;
}
Open in playground
Report an error