Given this REST API error response JSON, what is the value of the error.message field?
{
"error": {
"code": 404,
"message": "Resource not found",
"details": "The requested item does not exist."
}
}Look inside the error object for the message key.
The message key inside the error object holds the string describing the error, which is "Resource not found".
When a REST API receives invalid input data, which HTTP status code should it return to indicate a validation error?
Think about which status code means the client sent bad data.
400 Bad Request means the client sent invalid data, so it is the correct status code for validation errors.
Consider this JSON error response. What error will a JSON parser raise?
{
"error": {
"code": 401,
"message": "Unauthorized access",
"details": "Missing authentication token"
}
}Check the commas after the last item in JSON objects.
JSON does not allow a comma after the last key-value pair in an object. The trailing comma causes a SyntaxError.
Given this Python code snippet that processes an error response, what will be printed?
response = {
"error": {
"code": 403,
"message": "Forbidden",
"details": None
}
}
message = response.get("error", {}).get("message", "No error message")
print(message)Look at how the code safely accesses nested keys with get.
The code safely gets the "message" key inside "error". Since it exists, it prints "Forbidden".
To support multiple languages in error messages, which JSON error response structure is best?
Think about how to store messages in multiple languages clearly.
Option B uses a dictionary with language codes as keys, making it easy to select the right message for each user language.