Code Room
Code reviewMedium
Question
Review this JavaScript client that sends an idempotency key with each retry of a refund request.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
async function refund(orderId, amount) { for (let i = 0; i < 3; i++) { const key = crypto.randomUUID(); const res = await fetch("/refunds", { method: "POST", headers: { "Idempotency-Key": key }, body: JSON.stringify({ orderId, amount }), }); if (res.ok) return res.json(); } throw new Error("refund failed");}Run or narrate your approach, then ask the coach.