Bird
Raised Fist0

Examine this REST API function designed for graceful degradation:

medium📝 Debug Q6 of Q15
Rest API - Rate Limiting and Throttling
Examine this REST API function designed for graceful degradation:
async function fetchUserProfile() {
  try {
    const profile = await getFullProfile();
    return profile;
  } catch (error) {
    getBasicProfile();
  }
}

What is the key issue in this implementation?
AThe function does not log the error for debugging purposes.
BThe try block does not handle asynchronous errors properly.
CThe fallback function getBasicProfile() is called but its result is not returned.
DThe function should throw the error instead of catching it.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the try block

    The function awaits getFullProfile() and returns its result if successful.
  2. Step 2: Analyze the catch block

    In the catch block, getBasicProfile() is called but its result is not returned, so the function implicitly returns undefined.
  3. Final Answer:

    The fallback data is not returned, causing the function to fail graceful degradation. -> Option C
  4. Quick Check:

    Ensure fallback results are returned [OK]
Quick Trick: Always return fallback data in catch blocks [OK]
Common Mistakes:
MISTAKES
  • Ignoring the need to return fallback data
  • Assuming calling fallback function is enough
  • Not handling async errors properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes