checkKwikFormsHealth static method

Future<void> checkKwikFormsHealth()

Blocks until the backend confirms KwikPass is healthy; throws KwikFormsHealthException otherwise, so the gated call is never sent.

A healthy result is shared for _healthTtl, and concurrent callers share one in-flight request. Failures clear the cache immediately — they are never reused.

Implementation

static Future<void> checkKwikFormsHealth() {
  final cached = _healthInFlight;
  final checkedAt = _healthCheckedAt;
  if (cached != null &&
      checkedAt != null &&
      DateTime.now().difference(checkedAt) < _healthTtl) {
    return cached;
  }

  _healthCheckedAt = DateTime.now();
  final future = _doHealthCheck().catchError((Object error) {
    // Never cache an unhealthy/failed result.
    _healthInFlight = null;
    _healthCheckedAt = null;
    throw error;
  });
  _healthInFlight = future;
  return future;
}