0
0
Rest APIprogramming~10 mins

Error response structure 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 set the HTTP status code for an error response.

Rest API
response.status_code = [1]
Drag options to blanks, or click blank then click option'
A404
B200
C500
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 which means success.
Using 302 which is for redirection.
2fill in blank
medium

Complete the JSON error response body with the correct key for the error message.

Rest API
{
  "error": {
    "[1]": "Resource not found"
  }
}
Drag options to blanks, or click blank then click option'
Amessage
Bcode
Cstatus
Ddetail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'code' which usually holds numeric error codes.
Using 'status' which is often the HTTP status code.
3fill in blank
hard

Fix the error in the error response JSON by completing the missing key for the error code.

Rest API
{
  "error": {
    "[1]": 404,
    "message": "Not Found"
  }
}
Drag options to blanks, or click blank then click option'
Astatus
Bcode
Cerror_code
Dhttp_code
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' which can be confused with HTTP status.
Using 'http_code' which is less common.
4fill in blank
hard

Fill both blanks to create a complete error response with status and message keys.

Rest API
{
  "error": {
    "[1]": 401,
    "[2]": "Unauthorized access"
  }
}
Drag options to blanks, or click blank then click option'
Acode
Bmessage
Cstatus
Ddetail
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the keys or using uncommon key names.
5fill in blank
hard

Fill all three blanks to create a detailed error response with code, message, and details keys.

Rest API
{
  "error": {
    "[1]": 403,
    "[2]": "Forbidden",
    "[3]": "You do not have permission to access this resource."
  }
}
Drag options to blanks, or click blank then click option'
Acode
Bmessage
Cdetails
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'code'.
Confusing 'details' with 'message'.