Bird
0
0

This REST API code snippet is meant to provide graceful degradation but has a bug:

medium📝 Debug Q14 of 15
Rest API - Rate Limiting and Throttling
This REST API code snippet is meant to provide graceful degradation but has a bug:
function getData() {
  try {
    return fetchData();
  } catch (error) {
    fallbackData;
  }
}

What is the problem?
AThe try block is missing
BThe fallback data is not returned in the catch block
CThe function does not catch errors
DThe function returns twice
Step-by-Step Solution
Solution:
  1. Step 1: Check catch block code

    The catch block has fallbackData; but does not return it.
  2. Step 2: Understand function return behavior

    Without return, the function returns undefined on error, breaking graceful degradation.
  3. Final Answer:

    The fallback data is not returned in the catch block -> Option B
  4. Quick Check:

    Catch must return fallback data for graceful degradation [OK]
Quick Trick: Always return fallback data inside catch block [OK]
Common Mistakes:
  • Forgetting to return fallback data
  • Misplacing try-catch blocks
  • Assuming catch auto-returns value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes