Skip to main content
Mock HTTP Errors in Fiddler for Robust API Testing
Request Modification7 min read

Mock HTTP Errors in Fiddler for Robust API Testing

Learn how to mock HTTP errors in Fiddler using AutoResponder, RulesEngine, and latency simulation — essential for robust API and frontend testing.

Share:

Why Mocking HTTP Errors Matters in Real-World Development

Modern web applications depend on dozens of third-party APIs — payment gateways, identity providers, analytics services — all of which can fail unpredictably. Yet most frontend and mobile teams test only the happy path. When a 503 Service Unavailable hits production at 2 a.m., your error handling logic is tested for the first time — under fire. That’s unacceptable.

Fiddler’s response mocking capabilities let you simulate any HTTP status code, delay, malformed body, or TLS handshake failure — without modifying application code or relying on flaky staging environments. This is foundational fiddler debugging, especially for resilience validation, edge-case coverage, and offline testing. It’s also a core part of any serious http debugging workflow — not just for observing traffic, but for shaping it.

This tutorial walks through precise, repeatable techniques to mock error scenarios using Fiddler’s built-in tools: AutoResponder, RulesEngine, and custom C# scripts. You’ll learn how to trigger and verify client-side fallbacks, retry logic, and graceful degradation — all from your local machine.

Prerequisites: Enable HTTPS Decryption and Configure Your Proxy

Before mocking responses, ensure Fiddler captures all traffic — including encrypted HTTPS requests. Without proper setup, you’ll miss critical API calls or fail to inject errors into secure endpoints.

  1. Launch Fiddler → Tools > Options > HTTPS
  2. Check Decrypt HTTPS traffic
  3. Click Actions > Trust Root Certificate and complete the OS certificate import (Windows/macOS prompts differ)
  4. Confirm Ignore server certificate errors is enabled if testing self-signed dev APIs
  5. Verify your browser/app uses Fiddler as its system proxy (default: 127.0.0.1:8888)

This step is essential for reliable https decryption, particularly when mocking errors from OAuth providers or banking APIs that enforce strict TLS policies. If requests don’t appear in Fiddler’s session list, revisit certificate trust — it’s the #1 cause of silent capture failure.

For deeper control, consider enabling Allow remote computers to connect (under Connections) if testing iOS/Android devices. Just remember to restrict access via firewall rules in production-like setups.

Method 1: AutoResponder — Fast & Visual Error Injection

The AutoResponder is Fiddler’s quickest way to mock responses — ideal for static status codes and canned payloads.

Step-by-step: Return a 429 Too Many Requests

  1. Capture a real request to your target endpoint (e.g., POST https://api.example.com/v1/orders)
  2. Right-click the session → Copy > Just URL
  3. Open Rules > AutoResponder
  4. Click Add Rule
  5. Paste the URL into the Rule Pattern field
  6. Select Unmatched requests passthrough
  7. Click Add Response → choose Text Content
  8. Set status code to 429, reason to Too Many Requests
  9. Add headers:
    Retry-After: 60
    Content-Type: application/json
    
  10. Enter JSON body:
    {"error": "rate_limit_exceeded", "retry_after_seconds": 60}
    
  11. Check Enable rules and Unmatched requests passthrough

Now reissue the same request — Fiddler intercepts it and returns your mocked 429 instantly. No backend involved. This is pure fiddler proxy power: deterministic, repeatable, and safe.

💡 Pro tip: Use wildcards (*) in the Rule Pattern for broader matching: https://api.example.com/v1/* catches all v1 endpoints. Combine with regex (regex:^https://api\.example\.com/v1/orders.*) for precision.

Method 2: Custom RulesEngine Script — Dynamic Error Logic

AutoResponder works for fixed responses — but what if you need conditional behavior? For example: return 500 only on the 3rd call, or inject latency + error on POSTs to /checkout?

Fiddler’s RulesEngine (C#-based) handles this elegantly.

Step-by-step: Simulate Intermittent 500s

  1. Go to Rules > Customize Rules (opens CustomRules.js in Notepad)
  2. Locate the OnBeforeResponse function
  3. Insert this block before the final }:
if (oSession.uriContains("/api/v1/payment") && oSession.RequestMethod == "POST") {
    // Count occurrences
    var count = (int)FiddlerApplication.oUserContext["paymentErrorCount"];
    FiddlerApplication.oUserContext["paymentErrorCount"] = count + 1;

    if (count % 3 == 2) { // Fail every 3rd request
        oSession.utilCreateResponseAndBypassServer();
        oSession.responseCode = 500;
        oSession.Status = "500 Internal Server Error";
        oSession.utilSetResponseBody("{\"error\":\"unexpected_failure\"}");
        oSession.oResponse.headers.SetStatus(500, "Internal Server Error");
        oSession.oResponse.headers.Add("Content-Type", "application/json");
    }
}
  1. Save the file. Fiddler auto-compiles it.

Now each POST to /api/v1/payment increments a counter — and every third request gets a synthetic 500. Your app’s retry handler has no idea it’s talking to Fiddler, not a real service. This is advanced fiddler debugging, enabling realistic fault injection for chaos engineering lite.

⚠️ Troubleshooting: If rules don’t fire, confirm Rules > Enable Rules is checked. Use FiddlerApplication.Log.LogString() to debug values in the Log tab.

Method 3: Delay + Error — Test Timeouts and Race Conditions

Network errors aren’t always about status codes — latency spikes, abrupt disconnects, and partial responses break apps just as often.

Simulating a Timeout-Prone Endpoint

Use Fiddler’s Latency feature alongside AutoResponder:

  1. In AutoResponder, add a new rule matching your target URL
  2. Click Add Response > Simulate Latency
  3. Set Delay (ms) to 8000 (8 seconds)
  4. Check Abort connection after delay → this mimics a TCP timeout
  5. Also create a parallel rule with Text Content returning 504 Gateway Timeout — so you can toggle between behaviors

To validate timeout handling:

  • Set your app’s HTTP client timeout to 5s
  • Trigger the delayed rule
  • Observe whether your UI shows “Request timed out” vs. hanging indefinitely

This technique is indispensable for http debugging of mobile apps, where cellular networks introduce variable RTT and packet loss. Combine it with more tutorials on network throttling for full realism.

Method 4: Corrupt Responses — Test Faulty Parsing Logic

What happens when your JSON parser encounters malformed input? Or when a header contains unexpected characters? Don’t wait for production bugs — provoke them deliberately.

Example: Malformed JSON Response

  1. In AutoResponder, create a rule for GET https://api.example.com/v1/user/123
  2. Choose Text Content
  3. Set status 200 OK
  4. Paste intentionally broken JSON:
    {"id":123,"name":"Alice","email":"alice@example.com",} // trailing comma
    
  5. Add Content-Type: application/json

When your frontend attempts JSON.parse(), it throws — revealing whether you wrap fetch calls in try/catch, show generic errors, or crash silently. Similarly, test:

  • UTF-8 BOM in response body
  • Missing Content-Length header
  • Transfer-Encoding: chunked with invalid chunk sizes (via custom script)

These edge cases are rarely covered in unit tests — but they’re trivial to reproduce with Fiddler. It’s one of the most underrated uses of the fiddler proxy for quality assurance.

Bonus: Export & Share Mock Scenarios Across Teams

Testing error flows alone isn’t enough — your QA team, frontend devs, and SREs should all use identical scenarios.

Fiddler supports exporting AutoResponder rules:

  • Rules > AutoResponder > Save Rules… → saves .aor file
  • Share this file; colleagues import via Load Rules…

For RulesEngine scripts, commit CustomRules.cs to source control (yes — Fiddler supports .cs files too, with full IntelliSense in VS Code if you install the C# extension). This turns error mocking into versioned, auditable infrastructure.

You can even pair Fiddler with CI pipelines: launch headless Fiddler via CLI (Fiddler.exe -quit -register), load rules, run automated tests, then export logs. See our guide on browse Request Modification tutorials for automation patterns.

Conclusion: Build Resilience, Not Just Features

Error scenario testing isn’t QA overhead — it’s risk mitigation. Every 4xx and 5xx you simulate locally is one less outage post-deploy. With Fiddler, you own the network layer: you decide when services fail, how they fail, and how long they stay down.

Key takeaways:

  • Always enable https decryption first — no mocking works without full visibility
  • Use AutoResponder for rapid, visual mocking of static errors
  • Reach for RulesEngine scripts when you need state, randomness, or conditional logic
  • Combine delays, aborts, and malformed bodies to test timeouts, parsing, and race conditions
  • Treat mock rules like code: version them, share them, and reuse them across environments

Mastery of these techniques elevates your fiddler tutorial practice from passive observation to active experimentation. You’re no longer just watching HTTP — you’re orchestrating it.

Ready to go deeper? Explore our contact us page to request a workshop on advanced Fiddler scripting or enterprise-scale mocking strategies.

Share:

Related Topics

fiddler tutorialfiddler debugginghttp debuggingfiddler proxyhttps decryption

Get Fiddler Tips & Tutorials

Stay updated with the latest Fiddler tutorials, HTTP debugging guides, request modification tips, and web traffic analysis techniques.

Free forever. New tutorials published daily.

Related Articles