File tree 3 files changed +49
-13
lines changed
3 files changed +49
-13
lines changed Original file line number Diff line number Diff line change @@ -109,12 +109,25 @@ class IGCTextData {
109
109
fullText: content.text,
110
110
);
111
111
112
- final LanguageDetectionResponse detections = event.detections != null
113
- ? LanguageDetectionResponse .fromJson ({
112
+ LanguageDetectionResponse detections = defaultDetections;
113
+ if (event.detections != null ) {
114
+ try {
115
+ detections = LanguageDetectionResponse .fromJson ({
116
+ "detections" : event.detections,
117
+ "full_text" : content.text,
118
+ });
119
+ } catch (e, s) {
120
+ ErrorHandler .logError (
121
+ e: e,
122
+ s: s,
123
+ m: "Error parsing detections in IGCTextData.fromRepresentationEvent" ,
124
+ data: {
114
125
"detections" : event.detections,
115
126
"full_text" : content.text,
116
- })
117
- : defaultDetections;
127
+ },
128
+ );
129
+ }
130
+ }
118
131
119
132
return IGCTextData (
120
133
detections: detections,
Original file line number Diff line number Diff line change @@ -10,9 +10,20 @@ class LanguageDetection {
10
10
});
11
11
12
12
factory LanguageDetection .fromJson (Map <String , dynamic > json) {
13
+ final dynamic confValue = json[ModelKey .confidence];
14
+ double confidence;
15
+ if (confValue is String ) {
16
+ confidence = double .parse (confValue);
17
+ } else if (confValue is double ) {
18
+ confidence = confValue;
19
+ } else if (confValue is int ) {
20
+ confidence = confValue.toDouble ();
21
+ } else {
22
+ throw TypeError ();
23
+ }
13
24
return LanguageDetection (
14
25
langCode: json[ModelKey .langCode],
15
- confidence: json[ ModelKey . confidence] ,
26
+ confidence: confidence,
16
27
);
17
28
}
18
29
Original file line number Diff line number Diff line change @@ -510,14 +510,26 @@ class PangeaMessageEvent {
510
510
}
511
511
512
512
Future <String ?> representationByDetectedLanguage () async {
513
- final resp = await LanguageDetectionRepo .get (
514
- MatrixState .pangeaController.userController.accessToken,
515
- request: LanguageDetectionRequest (
516
- text: _latestEdit.body,
517
- senderl1: l1Code,
518
- senderl2: l2Code,
519
- ),
520
- );
513
+ LanguageDetectionResponse ? resp;
514
+ try {
515
+ resp = await LanguageDetectionRepo .get (
516
+ MatrixState .pangeaController.userController.accessToken,
517
+ request: LanguageDetectionRequest (
518
+ text: _latestEdit.body,
519
+ senderl1: l1Code,
520
+ senderl2: l2Code,
521
+ ),
522
+ );
523
+ } catch (e, s) {
524
+ ErrorHandler .logError (
525
+ e: e,
526
+ s: s,
527
+ data: {
528
+ "event" : _event.toJson (),
529
+ },
530
+ );
531
+ return null ;
532
+ }
521
533
522
534
final langCode = resp.detections.firstOrNull? .langCode;
523
535
if (langCode == null ) return null ;
You can’t perform that action at this time.
0 commit comments