Bird
0
0

Consider this pseudocode for a REST API endpoint:

medium📝 Predict Output Q5 of 15
Rest API - Rate Limiting and Throttling
Consider this pseudocode for a REST API endpoint:
try {
  data = fetchAllData();
  return { data: data, status: 200 };
} catch (error) {
  fallback = fetchPartialData();
  return { data: fallback, status: 206 };
}

What will the API return if fetchAllData() throws an error?
APartial data with status 206
BError message with status 500
CNo data with status 404
DFull data with status 200
Step-by-Step Solution
Solution:
  1. Step 1: Understand the try-catch flow

    If fetchAllData() throws an error, the catch block runs, fetching partial data.
  2. Step 2: Identify returned data and status in catch

    The catch returns partial data with status 206 Partial Content.
  3. Final Answer:

    Partial data with status 206 -> Option A
  4. Quick Check:

    Error triggers fallback with 206 status [OK]
Quick Trick: Errors trigger fallback data with 206 status [OK]
Common Mistakes:
  • Assuming error returns 500 status
  • Ignoring catch block fallback
  • Thinking full data is returned on error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes