0
0
Rest APIprogramming~10 mins

Error response format 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 return a JSON error response with a message.

Rest API
return {"error": [1]
Drag options to blanks, or click blank then click option'
A"Invalid request"
BInvalid request
C'Invalid request'
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the error message string.
Using single quotes instead of double quotes in JSON.
2fill in blank
medium

Complete 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'
A404
B"404"
C'404'
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the status code making it a string.
Using an incorrect status code number.
3fill in blank
hard

Fix 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'
Astatus
B"status"
C'status'
Dcode
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys in JSON causing syntax errors.
Using single quotes instead of double quotes for keys.
4fill in blank
hard

Fill 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'
A"Invalid input"
B400
C"400"
D'Invalid input'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Putting quotes around numeric status codes.
5fill in blank
hard

Fill 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'
A"Missing field"
B422
C["username", "password"]
D'Missing field'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings or keys.
Quoting numbers or arrays incorrectly.