0
0
Rest APIprogramming~10 mins

Nested error reporting in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a nested error message inside the main error response.

Rest API
{
  "error": {
    "message": "Invalid request",
    "details": [1]
  }
}
Drag options to blanks, or click blank then click option'
A["Missing field 'username'"]
Bnull
C{"field": "username"}
D"Missing field 'username'"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a string for the nested error message.
Leaving the details field as null.
2fill in blank
medium

Complete the code to include a nested error object with a code and message.

Rest API
{
  "error": {
    "message": "Validation failed",
    "details": {
      "code": [1],
      "message": "Email is invalid"
    }
  }
}
Drag options to blanks, or click blank then click option'
A400
Bnull
C"email_error"
D"400"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the number making it a string.
Using null instead of a code.
3fill in blank
hard

Fix the error in the nested error response by completing the missing key.

Rest API
{
  "error": {
    "message": "Request failed",
    "details": {
      [1]: "Missing required parameter 'id'"
    }
  }
}
Drag options to blanks, or click blank then click option'
A"code"
B"message"
C"error"
D"detail"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'code' instead of 'message' for the error description.
Using 'detail' which is not standard.
4fill in blank
hard

Fill both blanks to correctly nest multiple error messages inside the details array.

Rest API
{
  "error": {
    "message": "Multiple errors",
    "details": [
      {"field": [1], "message": "Required"},
      {"field": [2], "message": "Invalid format"}
    ]
  }
}
Drag options to blanks, or click blank then click option'
A"username"
B"email"
C"password"
D"id"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the fields in the wrong order.
Using fields not mentioned in the error messages.
5fill in blank
hard

Fill all three blanks to create a nested error response with a code, field, and message.

Rest API
{
  "error": {
    "code": [1],
    "details": {
      "field": [2],
      "message": [3]
    }
  }
}
Drag options to blanks, or click blank then click option'
A422
B"email"
C"Email is required"
D400
Attempts:
3 left
💡 Hint
Common Mistakes
Using 422 instead of 400 for the main error code.
Not quoting the field and message strings.