Docs

Simulating API Failures

Test your application's resilience by simulating various API failure scenarios. This guide shows you how to create realistic error conditions to ensure your app handles failures gracefully.

Creating Error Responses

Define custom error responses with specific status codes, messages, and response bodies to test how your frontend application handles different failure scenarios.

400 Bad Request

Invalid parameters or malformed request

401 Unauthorized

Missing or invalid authentication

404 Not Found

Resource does not exist

500 Server Error

Unexpected error on server

Setting up a custom error response with status code and message
Setting up a custom error response with status code and message

Configuring Failure Scenarios

Create complex failure scenarios like network timeouts, rate limiting, and partial data failures. Simulate intermittent issues to test retry logic and error recovery mechanisms.

Common Failure Types

Network timeouts and latency

Rate limiting with Retry-After headers

Malformed responses with partial data

Authentication failures with token expiration

Intermittent failures that occur randomly

Rate Limit Error Configuration

{
  "status": 429,
  "statusText": "Too Many Requests",
  "body": {
    "error": "rate_limit_exceeded",
    "message": "API rate limit exceeded",
    "retry_after": 30
  },
  "headers": {
    "Retry-After": "30",
    "X-RateLimit-Limit": "100",
    "X-RateLimit-Remaining": "0"
  },
  "delay": 1500
}

Editing & Expanding Endpoints

Modify existing endpoints to include failure cases or expand them with additional error handling logic. Evolve your test scenarios as your application develops.

Editing an existing endpoint to add failure cases
Editing an existing endpoint to add failure cases
Expanded view showing error configuration options
Expanded view showing error configuration options

Conditional Failures

Create sophisticated failure responses that only occur under specific conditions based on request parameters, headers, or body content.

Conditional Failure Logic

// Fail if request includes certain parameters
if (request.body && request.body.userId === "invalid") {
  return {
    status: 400,
    body: {
      error: "invalid_user",
      message: "The specified user ID is invalid"
    }
  };
}

// Fail if authorization header is missing or malformed
if (!request.headers.authorization || 
    !request.headers.authorization.startsWith("Bearer ")) {
  return {
    status: 401,
    body: {
      error: "unauthorized",
      message: "Valid authorization token required"
    }
  };
}

// Otherwise return success
return {
  status: 200,
  body: {
    success: true,
    data: { /* normal response data */ }
  }
};

Testing Tips

  • Test how your UI displays different error messages to users
  • Verify that your application's retry logic respects Retry-After headers
  • Check that authentication failures properly redirect to login screens
  • Ensure loading states and error states display correctly during timeouts

Testing Failure Responses

Test your configured failure scenarios using Postman or your application to verify that error handling works correctly.

Testing error responses with Postman
Testing error responses with Postman
Viewing error response details in Postman
Viewing error response details in Postman

Monitoring Error Responses

Track all simulated failures with comprehensive logging of status codes, response times, and error details to help with debugging.

Response monitoring dashboard showing error status codes
Response monitoring dashboard showing error status codes
Success Rate73%
0%50%100%

Key Benefits

By thoroughly testing how your application responds to API failures, you can build more robust software that gracefully handles unexpected conditions.

Resilient Applications

Ensure your app gracefully handles API failures and maintains a good user experience

Comprehensive Testing

Test complex edge cases and verify error handling before deploying to production

Better User Experience

Provide helpful error messages and recovery options instead of generic failure screens