Consider a REST API that returns this JSON error response when a user tries to access a resource without permission.
{
"error": {
"code": 403,
"message": "Access denied: You do not have permission to view this resource.",
"details": "User role 'guest' lacks 'read' permission."
}
}What is the message field in this error response?
Look for the exact text in the message field of the JSON.
The message field contains the human-readable explanation of the error. Here, it clearly states: "Access denied: You do not have permission to view this resource."
A REST API returns this JSON error when a requested item is not found:
{
"error": {
"code": 404,
"message": "Resource not found: The requested item does not exist.",
"details": "Item ID 12345 not found in database."
}
}What is the HTTP status code in this error response?
Check the code field inside the error object.
The code field shows the HTTP status code. Here it is 404, which means 'Not Found'.
A REST API returns this error JSON when the user sends invalid data:
{
"error": {
"code": 422,
"message": "Invalid input: 'email' field must be a valid email address.",
"details": "Value 'user_at_example.com' is not a valid email format."
}
}What is the exact message shown to the user?
Focus on the message field for the user-friendly explanation.
The message field provides a clear, human-readable explanation: "Invalid input: 'email' field must be a valid email address."
When the server encounters an unexpected error, it returns this JSON:
{
"error": {
"code": 500,
"message": "Internal server error: Please try again later.",
"details": "NullReferenceException at line 42."
}
}What is the message field value?
Look for the exact text in the message field.
The message field gives a user-friendly message: "Internal server error: Please try again later." The technical details are in the details field.
A REST API returns this JSON when authentication fails:
{
"error": {
"code": 401,
"message": "Authentication failed: Invalid API key provided.",
"details": "API key 'abc123' is not recognized."
}
}What is the exact message field value in this error response?
Check the message field for the user-friendly error text.
The message field clearly states: "Authentication failed: Invalid API key provided." This is the human-readable error message.