parseUiGraphAck function

UiGraphAck parseUiGraphAck(
  1. String? body
)

Decide whether a 2xx response actually means "stored".

Implementation

UiGraphAck parseUiGraphAck(String? body) {
  if (body == null || body.trim().isEmpty) {
    return const UiGraphAck(ok: false, error: 'ack_empty');
  }
  Object? decoded;
  try {
    decoded = jsonDecode(body);
  } catch (_) {
    return const UiGraphAck(ok: false, error: 'ack_unparseable');
  }
  if (decoded is! Map) {
    return const UiGraphAck(ok: false, error: 'ack_not_an_object');
  }
  final hasCounter = kAckCounterKeys.any(decoded.containsKey);
  if (!hasCounter) {
    return const UiGraphAck(ok: false, error: 'ack_missing_counters');
  }
  final rows = decoded['event_rows_written'];
  return UiGraphAck(
    ok: true,
    eventRowsWritten: rows is int ? rows : null,
  );
}