0
0
Rest APIprogramming~10 mins

Error codes for machine consumption 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 status code 404.

Rest API
return jsonify({"error": "Resource not found"}), [1]
Drag options to blanks, or click blank then click option'
A200
B404
C500
D403
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 means success, not error.
Using 500 means server error, not resource missing.
2fill in blank
medium

Complete the code to include an error code in the JSON response for a bad request.

Rest API
return jsonify({"error": "Bad request", "code": [1]), 400
Drag options to blanks, or click blank then click option'
A"BAD_REQUEST"
B"400"
C"ERR400"
D"BAD_REQ"
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric strings instead of descriptive codes.
Using unclear or inconsistent codes.
3fill in blank
hard

Fix the error in the JSON error response to include a machine-readable error code and message.

Rest API
response = {"message": "Unauthorized access", "error_code": [1]
return jsonify(response), 401
Drag options to blanks, or click blank then click option'
A401
B"401"
CUnauthorized
D"UNAUTHORIZED"
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric codes without quotes.
Using unquoted words causing syntax errors.
4fill in blank
hard

Fill both blanks to create a JSON error response with a code and a human message.

Rest API
return jsonify({"error": [1], "message": [2]), 403
Drag options to blanks, or click blank then click option'
A"FORBIDDEN"
B"Access denied"
C"Not allowed"
D"403"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping code and message values.
Using numeric codes as strings for messages.
5fill in blank
hard

Fill all three blanks to return a JSON error with code, message, and a numeric HTTP status.

Rest API
error_response = {"code": [1], "message": [2], "status": [3]
return jsonify(error_response), [3]
Drag options to blanks, or click blank then click option'
A"INVALID_INPUT"
B"Input data is invalid"
C422
D"422"
Attempts:
3 left
💡 Hint
Common Mistakes
Using status as a string instead of number.
Mixing up code and message values.