Spot the bug in the payment retry

from HTTP semantics
Node 24 intermediate 4 min 1 issue to find

Find the semantic bug in this generated payment retry.

JavaScript
async function createPayment(payment) {
  for (let attempt = 0; attempt < 3; attempt += 1) {
    try {
      return await fetch("https://payments.example/charges", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(payment),
      });
    } catch (error) {
      if (attempt === 2) throw error;
    }
  }
}
Open in playground
Report an error