CockpitFailure.fromJson constructor

CockpitFailure.fromJson(
  1. Object? value, {
  2. String path = r'$',
  3. CockpitDecodePolicy decodePolicy = CockpitDecodePolicy.requests,
})

Decodes a CockpitFailure from a JSON object.

Implementation

factory CockpitFailure.fromJson(
  Object? value, {
  String path = r'$',
  CockpitDecodePolicy decodePolicy = CockpitDecodePolicy.requests,
}) {
  final json = CockpitFoundationValueReader.object(value, path);
  CockpitFoundationValueReader.keys(
    json,
    const <String>{'primary', 'warnings'},
    path,
    required: const <String>{'primary'},
    policy: decodePolicy,
  );
  final rawWarnings = json['warnings'] == null
      ? const <Object?>[]
      : CockpitFoundationValueReader.list(json['warnings'], '$path.warnings');
  return CockpitFailure(
    primary: CockpitApiError.fromJson(
      json['primary'],
      path: '$path.primary',
      decodePolicy: decodePolicy,
    ),
    warnings: <CockpitApiWarning>[
      for (var index = 0; index < rawWarnings.length; index += 1)
        CockpitApiWarning.fromJson(
          rawWarnings[index],
          path: '$path.warnings[$index]',
          decodePolicy: decodePolicy,
        ),
    ],
  );
}