fix: In lemma definition request, use lemma.form if no lemma.text and log error to sentry (#1376)

pull/1593/head
ggurdin 10 months ago committed by GitHub
parent 350c9e6840
commit 7b1cccf78b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -524,7 +524,7 @@ class PangeaToken {
Future<List<String>> getEmojiChoices() => LemmaDictionaryRepo.get( Future<List<String>> getEmojiChoices() => LemmaDictionaryRepo.get(
LemmaDefinitionRequest( LemmaDefinitionRequest(
lemma: lemma.text, lemma: lemma,
partOfSpeech: pos, partOfSpeech: pos,
lemmaLang: MatrixState lemmaLang: MatrixState
.pangeaController.languageController.userL2?.langCode ?? .pangeaController.languageController.userL2?.langCode ??

@ -2,31 +2,40 @@ import 'dart:convert';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:fluffychat/pangea/models/lemma.dart';
import 'package:fluffychat/pangea/network/urls.dart'; import 'package:fluffychat/pangea/network/urls.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import '../config/environment.dart'; import '../config/environment.dart';
import '../network/requests.dart'; import '../network/requests.dart';
class LemmaDefinitionRequest { class LemmaDefinitionRequest {
final String lemma; final Lemma _lemma;
final String partOfSpeech; final String partOfSpeech;
final String lemmaLang; final String lemmaLang;
final String userL1; final String userL1;
LemmaDefinitionRequest({ LemmaDefinitionRequest({
required this.lemma,
required this.partOfSpeech, required this.partOfSpeech,
required this.lemmaLang, required this.lemmaLang,
required this.userL1, required this.userL1,
}); required Lemma lemma,
}) : _lemma = lemma;
factory LemmaDefinitionRequest.fromJson(Map<String, dynamic> json) { String get lemma {
return LemmaDefinitionRequest( if (_lemma.text.isNotEmpty) {
lemma: json['lemma'] as String, return _lemma.text;
partOfSpeech: json['part_of_speech'] as String, }
lemmaLang: json['lemma_lang'] as String, ErrorHandler.logError(
userL1: json['user_l1'] as String, e: "Found lemma with empty text",
data: {
'lemma': _lemma,
'part_of_speech': partOfSpeech,
'lemma_lang': lemmaLang,
'user_l1': userL1,
},
); );
return _lemma.form;
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

@ -21,7 +21,7 @@ class WordMeaningActivityGenerator {
); );
final LemmaDefinitionRequest lemmaDefReq = LemmaDefinitionRequest( final LemmaDefinitionRequest lemmaDefReq = LemmaDefinitionRequest(
lemma: lemmaId.lemma, lemma: req.targetTokens[0].lemma,
partOfSpeech: lemmaId.category, partOfSpeech: lemmaId.category,
/// This assumes that the user's L2 is the language of the lemma /// This assumes that the user's L2 is the language of the lemma

@ -20,7 +20,7 @@ class ContextualTranslationWidget extends StatelessWidget {
Future<String> _fetchDefinition() async { Future<String> _fetchDefinition() async {
final LemmaDefinitionRequest lemmaDefReq = LemmaDefinitionRequest( final LemmaDefinitionRequest lemmaDefReq = LemmaDefinitionRequest(
lemma: token.lemma.text, lemma: token.lemma,
partOfSpeech: token.pos, partOfSpeech: token.pos,
/// This assumes that the user's L2 is the language of the lemma /// This assumes that the user's L2 is the language of the lemma

@ -36,7 +36,7 @@ class LemmaDefinitionWidgetState extends State<LemmaDefinitionWidget> {
} else { } else {
final res = await LemmaDictionaryRepo.get( final res = await LemmaDictionaryRepo.get(
LemmaDefinitionRequest( LemmaDefinitionRequest(
lemma: widget.token.lemma.text, lemma: widget.token.lemma,
partOfSpeech: widget.token.pos, partOfSpeech: widget.token.pos,
lemmaLang: widget.tokenLang, lemmaLang: widget.tokenLang,
userL1: MatrixState userL1: MatrixState

Loading…
Cancel
Save