Challenge - 5 Problems
Error Response Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this JSON error response?
Given this error response from an API, what is the value of the
message field?Rest API
{
"error": {
"code": 404,
"message": "Resource not found",
"details": "The requested item does not exist."
}
}Attempts:
2 left
💡 Hint
Look inside the
error object for the message key.✗ Incorrect
The
message field inside the error object contains the string "Resource not found" which describes the error.🧠 Conceptual
intermediate1:00remaining
Which HTTP status code is best for a validation error?
You want to send an error response when user input is invalid. Which HTTP status code should you use?
Attempts:
2 left
💡 Hint
Think about which code means the client sent bad data.
✗ Incorrect
400 Bad Request means the server cannot process the request because of client error, such as invalid input.
🔧 Debug
advanced1:30remaining
What error does this JSON error response cause?
This API error response is sent as a string. What problem will the client face?
Rest API
"{ 'error': { 'code': 401, 'message': 'Unauthorized access' } }"Attempts:
2 left
💡 Hint
JSON requires double quotes for keys and strings.
✗ Incorrect
JSON must use double quotes for keys and string values. Single quotes cause a syntax error when parsing.
🚀 Application
advanced1:30remaining
How many fields are in this error response?
Count the total number of keys in this JSON error response object.
Rest API
{
"error": {
"code": 403,
"message": "Forbidden",
"details": {
"reason": "User lacks permission",
"timestamp": "2024-06-01T12:00:00Z"
}
},
"requestId": "abc123"
}Attempts:
2 left
💡 Hint
Count all keys at all levels inside the JSON object.
✗ Incorrect
The keys are: error, requestId, and inside error: code, message, details. Inside details: reason, timestamp. Total keys are 5 at top two levels (error, requestId, code, message, details). Nested keys inside details are not counted as separate top-level keys.
❓ Predict Output
expert2:00remaining
Which option produces this error response JSON string?
You want to produce this exact JSON string as an error response:
{"error":{"code":500,"message":"Internal Server Error"}}
Attempts:
2 left
💡 Hint
Check the exact keys and value types in the JSON string.
✗ Incorrect
Option C matches the exact keys and value types. Option C uses code as string, which changes the output. Option C adds an extra key. Option C uses 'msg' instead of 'message'.