0
0
Rest APIprogramming~20 mins

Error response format 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 error response from an API, what is the value of the message field?
Rest API
{
  "error": {
    "code": 404,
    "message": "Resource not found",
    "details": "The requested item does not exist."
  }
}
A"404"
B"Resource not found"
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 best for a validation error?
You want to send an error response when user input is invalid. Which HTTP status code should you use?
A200 OK
B404 Not Found
C500 Internal Server Error
D400 Bad Request
Attempts:
2 left
💡 Hint
Think about which code means the client sent bad data.
🔧 Debug
advanced
1:30remaining
What error does this JSON error response cause?
This API error response is sent as a string. What problem will the client face?
Rest API
"{ 'error': { 'code': 401, 'message': 'Unauthorized access' } }"
ASyntaxError due to single quotes in JSON string
BValueError because code is not a string
CTypeError because of missing error key
DNo error, valid JSON string
Attempts:
2 left
💡 Hint
JSON requires double quotes for keys and strings.
🚀 Application
advanced
1:30remaining
How many fields are in this error response?
Count the total number of keys in this JSON error response object.
Rest API
{
  "error": {
    "code": 403,
    "message": "Forbidden",
    "details": {
      "reason": "User lacks permission",
      "timestamp": "2024-06-01T12:00:00Z"
    }
  },
  "requestId": "abc123"
}
A5
B3
C6
D4
Attempts:
2 left
💡 Hint
Count all keys at all levels inside the JSON object.
Predict Output
expert
2:00remaining
Which option produces this error response JSON string?
You want to produce this exact JSON string as an error response: {"error":{"code":500,"message":"Internal Server Error"}}
Ajson.dumps({'error': {'code': 500, 'message': 'Internal Server Error'}, 'extra': None})
Bjson.dumps({'error': {'code': '500', 'message': 'Internal Server Error'}})
Cjson.dumps({'error': {'code': 500, 'message': 'Internal Server Error'}})
Djson.dumps({'error': {'code': 500, 'msg': 'Internal Server Error'}})
Attempts:
2 left
💡 Hint
Check the exact keys and value types in the JSON string.