Objective
A custom error can carry data (attributes) besides the message, so whoever catches it can decide what to do. Here we simulate calls to a service that sometimes fails.
Instructions
- The first line has the number
nof cases; each one is a line with the status codes the service would return on each attempt (for example503 500 200). - Make up to 3 attempts. Show
Attempt k: codefor each attempt. A code below 500 ends the calls: from 200 to 299 showSuccess; otherwiseRejected: code. If the 3 attempts give 5xx, raiseApiErrorwith the attributesstatusandattempts, and showFinal failure: code after 3 attempts.
3
503 500 200
404
500 502 503
Attempt 1: 503
Attempt 2: 500
Attempt 3: 200
Success
Attempt 1: 404
Rejected: 404
Attempt 1: 500
Attempt 2: 502
Attempt 3: 503
Final failure: 503 after 3 attempts
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise