0
0
Rest APIprogramming~20 mins

Error response structure in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Error Response Master
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 JSON error response?

Given this REST API error response JSON, what is the value of the error.message field?

Rest API
{
  "error": {
    "code": 404,
    "message": "Resource not found",
    "details": "The requested item does not exist."
  }
}
A"Resource not found"
B"404"
C"The requested item does not exist."
D"error"
Attempts:
2 left
💡 Hint

Look inside the error object for the message key.

🧠 Conceptual
intermediate
1:00remaining
Which HTTP status code is most appropriate for a validation error?

When a REST API receives invalid input data, which HTTP status code should it return to indicate a validation error?

A200 OK
B404 Not Found
C400 Bad Request
D500 Internal Server Error
Attempts:
2 left
💡 Hint

Think about which status code means the client sent bad data.

Predict Output
advanced
1:30remaining
What error does this JSON cause when parsed?

Consider this JSON error response. What error will a JSON parser raise?

Rest API
{
  "error": {
    "code": 401,
    "message": "Unauthorized access",
    "details": "Missing authentication token"
  }
}
ASyntaxError due to trailing comma
BKeyError for missing key
CTypeError due to wrong data type
DNo error, parses correctly
Attempts:
2 left
💡 Hint

Check the commas after the last item in JSON objects.

Predict Output
advanced
1:30remaining
What is the output of this error response handling code?

Given this Python code snippet that processes an error response, what will be printed?

Rest API
response = {
    "error": {
        "code": 403,
        "message": "Forbidden",
        "details": None
    }
}

message = response.get("error", {}).get("message", "No error message")
print(message)
ANo error message
BKeyError
CNone
DForbidden
Attempts:
2 left
💡 Hint

Look at how the code safely accesses nested keys with get.

🧠 Conceptual
expert
2:00remaining
Which error response structure best supports internationalization?

To support multiple languages in error messages, which JSON error response structure is best?

A{ "error": { "code": 500, "message": null } }
B{ "error": { "code": 500, "messages": { "en": "Internal server error", "es": "Error interno del servidor" } } }
C{ "error": { "code": 500, "message": ["Internal server error", "Error interno del servidor"] } }
D{ "error": { "code": 500, "message": "Internal server error" } }
Attempts:
2 left
💡 Hint

Think about how to store messages in multiple languages clearly.