How do you test API error handling and error response consistency?
- error handling
- consistency
- status codes
Answer it first, then compare. Nothing here is saved or scored.
Model answer
Every API should return consistent error shapes. Test: (1) All error responses follow the same schema (e.g., { error: { code, message, details } }). (2) Correct HTTP status codes: 400 for bad input, 401 for unauthorized, 403 for forbidden, 404 for not found, 409 for conflict, 422 for validation, 500 for server error. (3) Error messages are helpful but do not leak internals (no stack traces). (4) Validation errors include field-level details. (5) Rate limit errors include Retry-After.
What interviewers listen for
- Schema-first thinkingYou validate response shape before you assert on values, every time.
- Status-code literacyYou can defend why 401 vs 403 vs 422 matters for the consumer.
- Contract awarenessYou know when consumer-driven contract tests beat end-to-end checks.
- Auth fluencyYou can describe rotating tokens across parallel workers without secrets in logs.