Bird
0
0

Find the mistake in this nested error response:

medium📝 Debug Q7 of 15
Rest API - Error Handling

Find the mistake in this nested error response:

{
  "errors": [
    {
      "field": "email",
      "message": "Invalid"
    },
    {
      "field": "password",
      "message": {
        "length": "Too short",
        "complexity": "Weak"
      }
    }
  ]
}

AThe 'errors' key must be an object, not an array
BThe 'message' field should always be a string, not an object
CThe nested error messages must be inside 'field' key
DThe JSON is valid and has no mistakes
Step-by-Step Solution
Solution:
  1. Step 1: Check consistency of 'message' field types

    In the first error, 'message' is a string; in the second, it is an object, which is inconsistent.
  2. Step 2: Understand typical error response format

    Usually, 'message' should be a string; nested errors should be under a different key or structure.
  3. Final Answer:

    The 'message' field should always be a string, not an object -> Option B
  4. Quick Check:

    Consistent message types = strings [OK]
Quick Trick: Keep error message types consistent (strings) [OK]
Common Mistakes:
  • Assuming arrays are invalid for errors
  • Putting nested errors inside 'field' key
  • Ignoring type consistency

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes