Bird
Raised Fist0

How should a REST API handle multiple error conditions in one response for machine consumption?Choose the best JSON structure.

hard🚀 Application Q9 of Q15
Rest API - Error Handling

How should a REST API handle multiple error conditions in one response for machine consumption?

Choose the best JSON structure.

A{"error": "Multiple errors occurred"}
B{"errors": [{"code": "E001", "message": "Invalid email"}, {"code": "E002", "message": "Password too short"}]}
C{"code": "E001", "message": "Invalid email", "code2": "E002", "message2": "Password too short"}
D{"status": 400, "error": "Invalid email and password"}
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to represent multiple errors

    Using an array of error objects allows clear, structured multiple errors.
  2. Step 2: Evaluate JSON structures for clarity and machine readability

    {"errors": [{"code": "E001", "message": "Invalid email"}, {"code": "E002", "message": "Password too short"}]} uses an "errors" array with separate code and message for each error, ideal for machines.
  3. Final Answer:

    {"errors": [{"code": "E001", "message": "Invalid email"}, {"code": "E002", "message": "Password too short"}]} -> Option B
  4. Quick Check:

    Use array of error objects for multiple errors [OK]
Quick Trick: Use an array of error objects for multiple errors [OK]
Common Mistakes:
MISTAKES
  • Combining multiple errors in one string
  • Using duplicate keys in JSON
  • Not structuring errors for machine parsing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes