Overview
Decide which HTTP status codes an API client should retry with a Go switch, and avoid the empty case that silently does nothing because Go never falls through.
- a switch runs only the first matching case
- no break needed
- list values: case 502, 503:
Short Course
A Go switch runs only the first matching case, with no break needed. Trap:
cases never fall through, so an empty case 502: above case 503: does
nothing. List the values: case 502, 503:.
switch code {
case 200, 204:
return "ok"
case 301:
return "moved"
}
Task
Write Retryable(code int) bool: true for 408, 429, 500, 502, 503 and 504,
false otherwise. Example: Retryable(503) → true.
Test Suites
Pending
Next
Output