Drill

ProblemsTypeScript › payments

Should this call be retried

mediumpaymentsTypeScript

The gateway client decides whether a failed call is worth trying again, or whether retrying would only make things worse.

shouldRetry(status: int, attempt: int) → bool

Solve it in the editor →

Where you start

function shouldRetry(status: number, attempt: number): boolean {
  
}

Worked examples

CallResult
shouldRetry(500, 1)true
shouldRetry(429, 2)true
shouldRetry(503, 3)false
shouldRetry(404, 1)false

Hint

Deal with the attempt ceiling first, then the status.

Reference solution in TypeScript
function shouldRetry(status: number, attempt: number): boolean {
  if (attempt < 1 || attempt >= 3) return false;
  return status === 429 || (status >= 500 && status <= 599);
}

The same problem in another language

More payments problems in TypeScript