Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return a fallback message when the main API call fails.
Rest API
response = call_main_api() if not response: return [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the original response without checking if it failed.
Calling the main API again instead of returning a fallback message.
✗ Incorrect
When the main API call fails (response is None or False), we return a fallback message to inform the user gracefully.
2fill in blank
mediumComplete the code to call a backup API if the main API call fails.
Rest API
response = call_main_api() if not response: response = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the main API again instead of the backup.
Returning an error message instead of trying the backup.
✗ Incorrect
If the main API call fails, we try the backup API to keep the service working.
3fill in blank
hardFix the error in the code to handle API failure gracefully.
Rest API
try: data = call_main_api() except Exception: data = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Re-raising the exception instead of handling it.
Setting data to None without fallback.
✗ Incorrect
When the main API call raises an exception, we catch it and call the backup API to degrade gracefully.
4fill in blank
hardFill both blanks to create a dictionary with API data or fallback values.
Rest API
result = {
"status": [1],
"data": [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function call directly instead of a string for status.
Setting data to a string instead of None.
✗ Incorrect
We set status to 'success' and data to None as a fallback when no data is available.
5fill in blank
hardFill all three blanks to build a graceful degradation response dictionary.
Rest API
response = {
"status": [1],
"message": [2],
"data": [3]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' status when there is an error.
Providing data instead of None when service is down.
✗ Incorrect
When the service fails, status is 'error', message explains the issue, and data is None.