Bird
0
0

Given this error response JSON:

medium📝 Predict Output Q4 of 15
Rest API - Error Handling
Given this error response JSON:
{"error": {"code": 401, "message": "Unauthorized"}}

What HTTP status code should the server send along with this response?
A500
B200
C404
D401
Step-by-Step Solution
Solution:
  1. Step 1: Match error code in JSON with HTTP status code

    The code 401 means Unauthorized, so the HTTP status should be 401.
  2. Step 2: Eliminate other status codes

    200 means success, 404 means not found, 500 means server error, none match the error code.
  3. Final Answer:

    401 -> Option D
  4. Quick Check:

    HTTP status matches error code in response [OK]
Quick Trick: HTTP status code should match error code in JSON [OK]
Common Mistakes:
  • Sending 200 OK with error JSON
  • Confusing 404 with 401
  • Using 500 for client authorization errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes