Checkout inventory fetch lacks timeout
Review this JavaScript service-to-service call.
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.
0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1const INV_BASE = "https://inv.internal";
2
3async function fetchInventory(sku) {
4 const res = await fetch(`${INV_BASE}/sku/${sku}`);
5 if (!res.ok) {
6 throw new Error(`inventory ${res.status}`);
7 }
8 return res.json();
9}
10
11async function checkout(cart) {
12 const stock = await Promise.all(
13 cart.items.map((i) => fetchInventory(i.sku))
14 );
15 return reserveAll(cart, stock);
16}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.