Drill

ProblemsC# › payments

Should this call be retried

mediumpaymentsMathC#

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

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public bool ShouldRetry(int status, int attempt) {
    
}

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 C#
public bool ShouldRetry(int status, int attempt) {
    if (attempt < 1 || attempt >= 3) return false;
    return status == 429 || (status >= 500 && status <= 599);
}

The same problem in another language

More payments problems in C#