Bird
Raised Fist0
Rest APIprogramming~20 mins

Human-readable error messages in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Master of Human-readable REST API Errors
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this REST API error response?

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?

AUnauthorized access attempt detected.
BAccess denied: You do not have permission to view this resource.
CPermission error: guest role cannot read.
DError 403: Forbidden access.
Attempts:
2 left
💡 Hint

Look for the exact text in the message field of the JSON.

Predict Output
intermediate
1:30remaining
What HTTP status code is returned for a missing 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?

A500
B401
C400
D404
Attempts:
2 left
💡 Hint

Check the code field inside the error object.

Predict Output
advanced
2:00remaining
What is the user-friendly error message for invalid input?

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?

AInvalid input: 'email' field must be a valid email address.
BError 422: Unprocessable Entity.
CEmail format error: user_at_example.com is invalid.
DInput validation failed for email.
Attempts:
2 left
💡 Hint

Focus on the message field for the user-friendly explanation.

Predict Output
advanced
2:00remaining
What error message does this REST API return for server failure?

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?

ANullReferenceException occurred.
BServer error 500: Unexpected failure.
CInternal server error: Please try again later.
DService unavailable, try again.
Attempts:
2 left
💡 Hint

Look for the exact text in the message field.

Predict Output
expert
2:30remaining
What is the exact error message returned when authentication fails?

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?

AAuthentication failed: Invalid API key provided.
BError 401: Unauthorized access.
CAPI key abc123 is invalid.
DAccess denied due to invalid credentials.
Attempts:
2 left
💡 Hint

Check the message field for the user-friendly error text.

Practice

(1/5)
1.

What is the main purpose of human-readable error messages in a REST API?

easy
A. To confuse users with complex codes
B. To hide all error details from users
C. To make error messages as technical as possible
D. To explain problems in simple words for users

Solution

  1. Step 1: Understand the role of error messages

    Error messages should help users understand what went wrong.
  2. Step 2: Identify the best description

    Human-readable means simple and clear, not technical or confusing.
  3. Final Answer:

    To explain problems in simple words for users -> Option D
  4. Quick Check:

    Human-readable = simple explanation [OK]
Hint: Think: error messages should help, not confuse [OK]
Common Mistakes:
  • Choosing technical jargon instead of simple words
  • Assuming error messages should hide details
  • Confusing human-readable with code-only messages
2.

Which of the following is the correct JSON format for a human-readable error message in a REST API response?

{
  "error": {
    "code": 404,
    "message": "Resource not found"
  }
}
easy
A. { error: 404, message: 'Not found' }
B. { "error": { "code": 404, "message": "Resource not found" } }
C. { "code": 404, "msg": "Not found" }
D. { error_code: 404, error_message: 'Resource missing' }

Solution

  1. Step 1: Check JSON syntax correctness

    Valid JSON requires double quotes around keys and string values.
  2. Step 2: Match the expected structure

    The error object should contain code and message keys with clear names.
  3. Final Answer:

    { "error": { "code": 404, "message": "Resource not found" } } -> Option B
  4. Quick Check:

    Valid JSON with clear keys = { "error": { "code": 404, "message": "Resource not found" } } [OK]
Hint: Look for double quotes and clear key names in JSON [OK]
Common Mistakes:
  • Using single quotes instead of double quotes in JSON
  • Missing nested error object structure
  • Using incorrect key names like 'msg' or 'error_code'
3.

Given this API response code snippet, what will be the output message?

response = {
  "status": 400,
  "error": {
    "code": "INVALID_INPUT",
    "message": "Input value is not valid"
  }
}
print(response["error"]["message"])
medium
A. Input value is not valid
B. 400
C. INVALID_INPUT
D. KeyError

Solution

  1. Step 1: Access nested dictionary keys

    response["error"] gives the nested dictionary, then ["message"] accesses the message string.
  2. Step 2: Print the message value

    The value of response["error"]["message"] is "Input value is not valid".
  3. Final Answer:

    Input value is not valid -> Option A
  4. Quick Check:

    Nested key access = message string [OK]
Hint: Follow dictionary keys step-by-step to find the message [OK]
Common Mistakes:
  • Printing the error code instead of message
  • Confusing status code with error message
  • Trying to access keys incorrectly causing KeyError
4.

Identify the error in this REST API error response JSON and fix it for proper human-readable message format:

{
  error: {
    code: 401,
    message: 'Unauthorized access'
  }
}
medium
A. Remove the error object and keep only code and message
B. Change code 401 to string '401'
C. Replace single quotes with double quotes and add quotes around keys
D. Add a status key with value 'error'

Solution

  1. Step 1: Check JSON syntax rules

    JSON keys and string values must be in double quotes, not single quotes or unquoted.
  2. Step 2: Fix the JSON format

    Add double quotes around keys (error, code, message) and change single quotes to double quotes.
  3. Final Answer:

    Replace single quotes with double quotes and add quotes around keys -> Option C
  4. Quick Check:

    Valid JSON needs double quotes on keys and strings [OK]
Hint: JSON keys and strings always need double quotes [OK]
Common Mistakes:
  • Using single quotes for strings in JSON
  • Leaving keys unquoted causing syntax errors
  • Changing numeric codes to strings unnecessarily
5.

You want to design a REST API error response that helps users fix input errors quickly. Which approach is best?

{
  "error": {
    "code": "INVALID_EMAIL",
    "message": "Email format is incorrect",
    "field": "email",
    "suggestion": "Use a valid email like user@example.com"
  }
}
hard
A. Include error code, message, field name, and suggestion for fix
B. Only include a generic error message without details
C. Return HTTP 200 status with error details inside
D. Send error details only in server logs, not in response

Solution

  1. Step 1: Identify helpful error response elements

    Clear code, message, field, and suggestion guide users to fix errors.
  2. Step 2: Compare options for user-friendliness

    Include error code, message, field name, and suggestion for fix provides detailed, human-readable info; others hide or confuse users.
  3. Final Answer:

    Include error code, message, field name, and suggestion for fix -> Option A
  4. Quick Check:

    Detailed, clear errors improve user experience [OK]
Hint: Add suggestions and field info for clearer error messages [OK]
Common Mistakes:
  • Returning generic messages without guidance
  • Using HTTP 200 for errors causing confusion
  • Hiding error details from users