Bird
Raised Fist0

An API returns error responses in varying formats: sometimes plain text, other times JSON objects. What is the recommended approach to improve error handling?

medium📝 Debug Q7 of Q15
Rest API - Error Handling
An API returns error responses in varying formats: sometimes plain text, other times JSON objects. What is the recommended approach to improve error handling?
AReturn errors only as plain text for simplicity
BAllow clients to parse errors differently based on the response type
CStandardize all error responses to a consistent JSON structure
DUse XML format for all error messages
Step-by-Step Solution
Solution:
  1. Step 1: Identify inconsistency

    Errors are returned in multiple formats, causing parsing difficulties.
  2. Step 2: Choose a single format

    Standardizing on a JSON structure ensures clients can reliably parse errors.
  3. Final Answer:

    Standardize all error responses to a consistent JSON structure -> Option C
  4. Quick Check:

    Consistent format simplifies client error handling [OK]
Quick Trick: Use one error format for all responses [OK]
Common Mistakes:
MISTAKES
  • Assuming clients can handle multiple formats automatically
  • Returning plain text errors for complex APIs
  • Switching formats based on error type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes