API API Error Handling and Debugging 1 — Questions and Answers
Question 1: What is a 400 Bad Request status code used for?
- Server failure
- The client sent a malformed or invalid request (Correct answer)
- Resource not found
- Authentication failure
Correct answer: The client sent a malformed or invalid request
400 Bad Request indicates the server cannot process the request due to client-side errors like invalid syntax, missing parameters, or malformed JSON.
Question 2: What does a 422 Unprocessable Entity response typically indicate?
- Server overload
- The request is well-formed but contains semantic errors or validation failures (Correct answer)
- Network timeout
- Authentication expired
Correct answer: The request is well-formed but contains semantic errors or validation failures
422 Unprocessable Entity means the request was syntactically correct but semantically invalid — validation rules were violated.
Question 3: What is the recommended structure for API error response bodies?
- Just an HTTP status code
- A structured object with error code, message, and details (Correct answer)
- Plain text description
- An empty body
Correct answer: A structured object with error code, message, and details
Best practice error responses include a structured object with a machine-readable error code, human-readable message, and optional details for debugging.
Question 4: What does a 503 Service Unavailable response indicate?
- Client authentication failure
- The server is temporarily unable to handle the request (Correct answer)
- Resource not found
- Request timeout on client side
Correct answer: The server is temporarily unable to handle the request
503 Service Unavailable indicates the server is temporarily unable to handle the request, often due to maintenance or overload.
Question 5: Which tool can be used to inspect raw HTTP API request and response traffic?
- Git
- Charles Proxy or Wireshark (Correct answer)
- Docker
- Jenkins
Correct answer: Charles Proxy or Wireshark
Charles Proxy and Wireshark are tools for capturing and inspecting raw HTTP/HTTPS traffic, invaluable for debugging API communication.
Question 6: What is a 'correlation ID' (request ID) in API error handling?
- A database foreign key
- A unique identifier per request enabling cross-system log tracing (Correct answer)
- A user session token
- An API version identifier
Correct answer: A unique identifier per request enabling cross-system log tracing
A correlation ID is a unique identifier attached to each API request and propagated through all systems, enabling end-to-end log tracing for debugging.
What is a 400 Bad Request status code used for?