Bird
0
0

Find the error in this retry logic snippet:

medium📝 Debug Q14 of 15
Rest API - Webhooks and Events

Find the error in this retry logic snippet:

def fetch_data():
    retries = 3
    while retries > 0:
        response = api_call()
        if response.status_code == 200:
            return response.data
        retries -= 1
    return None
    retries -= 1
AThe last line decreases retries after return, unreachable code
BMissing sleep between retries
CNo check for network exceptions
DShould use for loop instead of while
Step-by-Step Solution
Solution:
  1. Step 1: Review code flow

    The last line retries -= 1 is after return None, so it never runs.
  2. Step 2: Identify unreachable code problem

    Code after return is unreachable and unnecessary, indicating a logic error.
  3. Final Answer:

    The last line decreases retries after return, unreachable code -> Option A
  4. Quick Check:

    Code after return is unreachable [OK]
Quick Trick: Code after return is never executed [OK]
Common Mistakes:
MISTAKES
  • Ignoring unreachable code warnings
  • Forgetting to add wait between retries
  • Not handling exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes