Merge pull request #792 from pangeachat/activity-from-json-handling

better error handling for null content in practice activity fromJSON …
This commit is contained in:
ggurdin 2024-10-22 09:23:43 -04:00 committed by GitHub
commit 09316b8339
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
import 'package:fluffychat/pangea/models/practice_activities.dart/multiple_choice_activity_model.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/foundation.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
class ConstructIdentifier {
final String lemma;
@ -186,8 +187,15 @@ class PracticeActivityModel {
// moving from multiple_choice to content as the key
// this is to make the model more generic
// here for backward compatibility
final Map<String, dynamic> content =
(json['content'] ?? json["multiple_choice"]) as Map<String, dynamic>;
final Map<String, dynamic>? content =
(json['content'] ?? json["multiple_choice"]) as Map<String, dynamic>?;
if (content == null) {
Sentry.addBreadcrumb(
Breadcrumb(data: {"json": json}),
);
throw ("content is null in PracticeActivityModel.fromJson");
}
return PracticeActivityModel(
tgtConstructs: ((json['tgt_constructs'] ?? json['target_constructs'])