parseAnswersPlan static method

SyniAnswersPlan parseAnswersPlan(
  1. String raw
)

Parses syni_answers_plan_json's output. Public for tests.

Implementation

static SyniAnswersPlan parseAnswersPlan(String raw) {
  final dynamic decoded;
  try {
    decoded = jsonDecode(raw);
  } on FormatException catch (e) {
    throw SyniRuntimeError.protocol(
        'answers plan was not JSON: ${e.message}');
  }
  if (decoded is! Map) {
    throw SyniRuntimeError.protocol('answers plan was not an object');
  }
  if (decoded['ok'] == false) {
    final error = decoded['error'];
    throw SyniRuntimeError.fromEnvelope(
      error is Map
          ? error.cast<String, dynamic>()
          : const <String, dynamic>{},
    );
  }
  return SyniAnswersPlan.fromMap(decoded);
}