Critical Requests

Selectively capture only the failures that matter most to your application.

Default Behavior

By default, EndpointVault captures all failed requests. This is the simplest setup and works well for most applications:

final dio = Dio();
dio.interceptors.add(EndpointVaultInterceptor());

// All failed requests are automatically captured
await dio.get('/api/users');      // Captured on failure
await dio.post('/api/orders');    // Captured on failure
await dio.put('/api/settings');   // Captured on failure

When to Use Critical-Only Mode

Enable critical-only mode when you want fine-grained control over which failures to track. Common scenarios:

Enabling Critical-Only Mode

Set onlyCritical: true when creating the interceptor:

final dio = Dio();
dio.interceptors.add(EndpointVaultInterceptor(
  onlyCritical: true,  // Only capture requests marked as critical
));

Now only requests explicitly marked as critical will be captured on failure.

Marking Requests as Critical

There are two ways to mark a request as critical:

Option 1: Using the extra parameter

await dio.post('/api/payment',
  data: paymentData,
  options: Options(extra: {'ev_critical': true}),
);

Option 2: Using the extension method

await dio.post('/api/payment',
  data: paymentData,
  options: Options().critical(),
);

You can also add context information that will be included in the captured event:

await dio.post('/api/payment',
  data: paymentData,
  options: Options().critical(context: 'checkout_flow'),
);

Combining with Success Statistics

Even in critical-only mode, you can still capture success statistics for all endpoints:

dio.interceptors.add(EndpointVaultInterceptor(
  onlyCritical: true,        // Only capture critical failures
  captureSuccessStats: true, // But track success rates for all endpoints
));

This gives you endpoint health metrics in the dashboard while only storing detailed failure data for critical requests.

Tip: The context parameter in .critical(context: 'value') is useful for filtering events in the dashboard. Use it to identify which flow or feature triggered the request.

Example: E-commerce App

class ApiClient {
  final Dio dio;

  ApiClient() : dio = Dio() {
    dio.interceptors.add(EndpointVaultInterceptor(
      onlyCritical: true,
      captureSuccessStats: true,
    ));
  }

  // Critical: Payment processing
  Future<void> processPayment(PaymentData data) async {
    await dio.post('/api/payments',
      data: data.toJson(),
      options: Options().critical(context: 'payment'),
    );
  }

  // Critical: Order creation
  Future<Order> createOrder(OrderData data) async {
    final response = await dio.post('/api/orders',
      data: data.toJson(),
      options: Options().critical(context: 'order_creation'),
    );
    return Order.fromJson(response.data);
  }

  // Not critical: Product browsing
  Future<List<Product>> getProducts() async {
    final response = await dio.get('/api/products');
    return (response.data as List).map((p) => Product.fromJson(p)).toList();
  }

  // Not critical: User preferences
  Future<void> updatePreferences(Map<String, dynamic> prefs) async {
    await dio.put('/api/preferences', data: prefs);
  }
}
Remember: In critical-only mode, non-critical requests that fail will NOT be captured. Make sure to mark all important endpoints as critical.