Bird
Raised Fist0
Rest APIprogramming~20 mins

Nested error reporting in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Nested Error Reporting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this nested error response JSON?
Given this nested error response from a REST API, what is the value of the message field inside the details object?
Rest API
{
  "error": {
    "code": 400,
    "message": "Validation Failed",
    "details": {
      "field": "email",
      "message": "Invalid email format"
    }
  }
}
A"Validation Failed"
B"Invalid email format"
C"email"
D400
Attempts:
2 left
💡 Hint
Look inside the nested 'details' object for the 'message' field.
Predict Output
intermediate
1:30remaining
What HTTP status code is returned in this nested error response?
Look at this nested error response JSON. What is the HTTP status code indicated by the status field inside the error object?
Rest API
{
  "error": {
    "status": 404,
    "message": "Resource not found",
    "details": {
      "resource": "user",
      "id": "123"
    }
  }
}
A404
B"Resource not found"
C123
D"user"
Attempts:
2 left
💡 Hint
The status code is usually a number inside the 'error' object.
🔧 Debug
advanced
2:00remaining
Which option causes a JSON parsing error?
One of these nested error response JSON strings is invalid and will cause a parsing error. Which one?
A{ "error": { "code": 403, "message": "Forbidden", "details": { "action": "Access denied" } } }
B{ "error": { "code": 500, "message": "Server error", "details": { "info": "Unexpected failure" } } }
C{ "error": { "code": 400, "message": "Bad request", "details": { "field": "name", "message": "Missing value" } }
D{ "error": { "code": 401, "message": "Unauthorized", "details": { "reason": "Token expired" } } }
Attempts:
2 left
💡 Hint
Look for missing or extra brackets in the JSON strings.
🧠 Conceptual
advanced
1:30remaining
What is the main benefit of nesting error details in REST API responses?
Why do REST APIs often nest detailed error information inside an 'error' object rather than placing all fields at the top level?
ATo reduce the size of the response by nesting fields
BTo confuse the client and make debugging harder
CTo make the response invalid JSON intentionally
DTo organize error information clearly and separate it from other response data
Attempts:
2 left
💡 Hint
Think about clarity and structure in data.
Predict Output
expert
2:00remaining
What is the value of 'error.details.errors[1].message' in this nested error response?
Given this nested error response JSON, what is the value of the second error message inside the 'errors' list?
Rest API
{
  "error": {
    "code": 422,
    "message": "Validation Error",
    "details": {
      "errors": [
        {"field": "username", "message": "Required field"},
        {"field": "password", "message": "Too short"},
        {"field": "email", "message": "Invalid format"}
      ]
    }
  }
}
A"Too short"
B"Invalid format"
C"Required field"
D"Validation Error"
Attempts:
2 left
💡 Hint
Remember that list indexes start at 0.

Practice

(1/5)
1.

What is the main purpose of nested error reporting in REST APIs?

easy
A. To show detailed errors inside nested data clearly
B. To hide errors from users
C. To speed up the API response time
D. To encrypt error messages

Solution

  1. Step 1: Understand error reporting basics

    Error reporting helps identify problems in API requests or responses.
  2. Step 2: Recognize nested error reporting role

    Nested error reporting shows errors inside complex or nested data structures clearly.
  3. Final Answer:

    To show detailed errors inside nested data clearly -> Option A
  4. Quick Check:

    Nested error reporting = detailed nested errors [OK]
Hint: Nested errors explain problems inside complex data [OK]
Common Mistakes:
  • Thinking nested errors hide problems
  • Confusing error reporting with encryption
  • Assuming it speeds up API responses
2.

Which JSON structure correctly represents a nested error for a REST API response?

{
  "error": {
    "message": "Invalid input",
    "details": {
      "field": "email",
      "error": "Invalid format"
    }
  }
}
easy
A. { "error": "Invalid input", "details": "email error" }
B. { "message": "Invalid input", "field": "email" }
C. { "error": ["Invalid input", "email error"] }
D. { "error": { "message": "Invalid input", "details": { "field": "email", "error": "Invalid format" } } }

Solution

  1. Step 1: Identify nested JSON error format

    Nested error reporting uses objects inside objects to show details clearly.
  2. Step 2: Match the correct JSON structure

    { "error": { "message": "Invalid input", "details": { "field": "email", "error": "Invalid format" } } } shows an error object with a message and nested details object with field and error.
  3. Final Answer:

    { "error": { "message": "Invalid input", "details": { "field": "email", "error": "Invalid format" } } } -> Option D
  4. Quick Check:

    Nested JSON error = { "error": { "message": "Invalid input", "details": { "field": "email", "error": "Invalid format" } } } [OK]
Hint: Look for nested objects inside error key [OK]
Common Mistakes:
  • Using arrays instead of objects for nested errors
  • Missing nested details object
  • Flattening error info without nesting
3.

Given this REST API error response JSON, what is the error message for the password field?

{
  "error": {
    "message": "Validation failed",
    "fields": {
      "email": "Invalid format",
      "password": "Too short"
    }
  }
}
medium
A. Validation failed
B. Invalid format
C. Too short
D. No error

Solution

  1. Step 1: Locate the password field in JSON

    The password error is inside error.fields.password.
  2. Step 2: Read the error message for password

    The value is "Too short", indicating the password error.
  3. Final Answer:

    Too short -> Option C
  4. Quick Check:

    password error message = "Too short" [OK]
Hint: Find error under error.fields.password [OK]
Common Mistakes:
  • Choosing top-level message instead of field error
  • Confusing email error with password error
  • Ignoring nested fields object
4.

Identify the error in this nested error JSON response:

{
  "error": {
    "message": "Invalid data",
    "details": [
      { "field": "username", "error": "Required" },
      { "field": "age", "error": 25 }
    ]
  }
}
medium
A. The 'error' value for 'age' should be a string, not a number
B. The 'details' key should be a string, not an array
C. The 'message' key is missing
D. The 'field' keys should be numbers

Solution

  1. Step 1: Check error value types in details array

    Each error value should be a descriptive string, not a number.
  2. Step 2: Identify incorrect error value

    The 'age' field has error value 25 (number), which is incorrect.
  3. Final Answer:

    The 'error' value for 'age' should be a string, not a number -> Option A
  4. Quick Check:

    Error values must be strings [OK]
Hint: Error messages must be strings, not numbers [OK]
Common Mistakes:
  • Ignoring type mismatch in error values
  • Thinking details must be string instead of array
  • Missing the message key
5.

You want to design a nested error response for a REST API that validates a user profile with nested address fields. Which JSON structure best represents errors for both the email and nested address.zipcode fields?

hard
A. { "error": { "email": "Invalid", "address.zipcode": "Missing" } }
B. { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } }
C. { "error": [ { "email": "Invalid" }, { "address": { "zipcode": "Missing" } } ] }
D. { "error": "Invalid email and missing zipcode" }

Solution

  1. Step 1: Understand nested error reporting for nested fields

    Nested fields like address.zipcode should be represented as nested objects.
  2. Step 2: Evaluate JSON options for nested structure

    { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } } uses a 'fields' object with 'email' error and nested 'address' object containing 'zipcode' error.
  3. Final Answer:

    { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } } -> Option B
  4. Quick Check:

    Nested fields use nested objects = { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } } [OK]
Hint: Use nested objects for nested field errors [OK]
Common Mistakes:
  • Using dot notation keys instead of nested objects
  • Flattening nested errors into arrays
  • Combining all errors into one string