Bird
Raised Fist0

Analyze this REST API error response code snippet:

medium📝 Debug Q7 of Q15
Rest API - Error Handling

Analyze this REST API error response code snippet:

return {"status": 503, "error": "Service Unavailable"}, 200

What is the issue with this implementation?

AThe HTTP status code returned is 200 instead of 503
BThe error message should be 'Internal Server Error' instead
CThe status field should be a string, not a number
DThe error key should be named 'message' instead
Step-by-Step Solution
Solution:
  1. Step 1: Understand HTTP status codes

    503 indicates service unavailable, but the snippet returns HTTP 200.
  2. Step 2: Identify mismatch

    The response body says 503 but the actual HTTP status is 200, which is misleading.
  3. Final Answer:

    The HTTP status code returned is 200 instead of 503 -> Option A
  4. Quick Check:

    HTTP status must match error code [OK]
Quick Trick: HTTP status code must reflect error [OK]
Common Mistakes:
MISTAKES
  • Ignoring the HTTP status code and relying on body only
  • Confusing error message text with status code
  • Using string instead of numeric status code (not critical here)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes