Skip to main content

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 thinking
    You validate response shape before you assert on values, every time.
  • Status-code literacy
    You can defend why 401 vs 403 vs 422 matters for the consumer.
  • Contract awareness
    You know when consumer-driven contract tests beat end-to-end checks.
  • Auth fluency
    You can describe rotating tokens across parallel workers without secrets in logs.

See all 35 api testing questions

Written by , Senior QA Automation Engineer, 50+ QA candidate interviews conductedLast updated July 2026