Review this generated change for an intermittent cross-tenant profile bug.
Instrument profile loading without exposing credentials or changing retry behavior, keep cached profiles isolated by tenant and user, preserve HTTP failure semantics, and collect bounded evidence about cache decisions.
JavaScript
const cache = new Map();
export async function loadProfile(tenantId, userId, token) {
const key = userId;
if (cache.has(key)) {
console.log("cache hit", { tenantId, userId, token });
return cache.get(key);
}
const started = Date.now();
try {
const response = await fetch(
`/api/${tenantId}/profiles/${userId}`,
{ headers: { authorization: `Bearer ${token}` } },
);
const profile = await response.json();
cache.set(key, profile);
console.log("loaded", { userId, elapsed: Date.now() - started });
return profile;
} catch (error) {
console.log("retrying", { tenantId, userId, error });
return loadProfile(tenantId, userId, token);
}
}
generated code is illustrative, not from any one model