Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return a JSON error response with a message.
Rest API
return {"error": [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the error message string.
Using single quotes instead of double quotes in JSON.
✗ Incorrect
The error message must be a string inside quotes in JSON format.
2fill in blank
mediumComplete the code to include an HTTP status code in the error response.
Rest API
return {"error": "Not found", "status": [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the status code making it a string.
Using an incorrect status code number.
✗ Incorrect
The status code should be a number, not a string, in the JSON response.
3fill in blank
hardFix the error in the JSON error response format.
Rest API
return {"error": "Unauthorized", [1]: 401}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys in JSON causing syntax errors.
Using single quotes instead of double quotes for keys.
✗ Incorrect
JSON keys must be strings enclosed in double quotes.
4fill in blank
hardFill both blanks to create a detailed error response with message and code.
Rest API
return {"message": [1], "code": [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Putting quotes around numeric status codes.
✗ Incorrect
The message must be a string with double quotes, and the code must be a number.
5fill in blank
hardFill all three blanks to return an error with message, code, and details.
Rest API
return {"message": [1], "code": [2], "details": [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings or keys.
Quoting numbers or arrays incorrectly.
✗ Incorrect
Message is a string with double quotes, code is a number, details is a JSON array.