diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index 973a89747..9ccb197ee 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -406,8 +406,7 @@ class Choreographer { PangeaTextController get textController => _textController; - Future get accessToken => - pangeaController.userController.accessToken; + Future get accessToken => pangeaController.userController.accessToken; clear() { choreoMode = ChoreoMode.igc; diff --git a/lib/pangea/choreographer/widgets/it_feedback_card.dart b/lib/pangea/choreographer/widgets/it_feedback_card.dart index 840843ed5..4285f4dca 100644 --- a/lib/pangea/choreographer/widgets/it_feedback_card.dart +++ b/lib/pangea/choreographer/widgets/it_feedback_card.dart @@ -73,15 +73,7 @@ class ITFeedbackCardController extends State { isTranslating = true; }); - final String? accessToken = await controller.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - m: "Cannot translate feedback because accessToken is null", - ); - error = "Cannot translate feedback because accessToken is null"; - return; - } - + final String accessToken = await controller.userController.accessToken; FullTextTranslationRepo.translate( accessToken: accessToken, request: FullTextTranslationRequestModel( diff --git a/lib/pangea/controllers/contextual_definition_controller.dart b/lib/pangea/controllers/contextual_definition_controller.dart index ecc08a234..68e075d97 100644 --- a/lib/pangea/controllers/contextual_definition_controller.dart +++ b/lib/pangea/controllers/contextual_definition_controller.dart @@ -50,13 +50,6 @@ class ContextualDefinitionController { ) async { try { final accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in contextual definition controller", - s: StackTrace.current, - ); - return null; - } final ContextualDefinitionResponseModel res = await _ContextualDefinitionRepo.define( accessToken, diff --git a/lib/pangea/controllers/it_feedback_controller.dart b/lib/pangea/controllers/it_feedback_controller.dart index c2cd96cad..74aee21de 100644 --- a/lib/pangea/controllers/it_feedback_controller.dart +++ b/lib/pangea/controllers/it_feedback_controller.dart @@ -51,15 +51,8 @@ class ITFeedbackController { ITFeedbackRequestModel request, ) async { try { - final String? accessToken = + final String accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in it feedback controller", - s: StackTrace.current, - ); - return null; - } final ITFeedbackResponseModel res = await _ITFeedbackRepo.get( accessToken, request, diff --git a/lib/pangea/controllers/language_detection_controller.dart b/lib/pangea/controllers/language_detection_controller.dart index 5ba0f8879..ecbdea47d 100644 --- a/lib/pangea/controllers/language_detection_controller.dart +++ b/lib/pangea/controllers/language_detection_controller.dart @@ -6,7 +6,6 @@ import 'package:fluffychat/pangea/constants/language_constants.dart'; import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; import 'package:fluffychat/pangea/models/language_detection_model.dart'; import 'package:fluffychat/pangea/network/urls.dart'; -import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:http/http.dart' as http; import '../network/requests.dart'; @@ -145,15 +144,8 @@ class LanguageDetectionController { if (_cache.containsKey(params)) { return _cache[params]!.data; } else { - final String? accessToken = + final String accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in language detection controller", - s: StackTrace.current, - ); - return null; - } final Future response = _fetchResponse( accessToken, params, diff --git a/lib/pangea/controllers/message_data_controller.dart b/lib/pangea/controllers/message_data_controller.dart index 7ad3a748f..aa0c77b9d 100644 --- a/lib/pangea/controllers/message_data_controller.dart +++ b/lib/pangea/controllers/message_data_controller.dart @@ -43,15 +43,6 @@ class MessageDataController extends BaseController { TokensRequestModel req, ) async { final accessToken = await _pangeaController.userController.accessToken; - - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in _getTokens", - s: StackTrace.current, - ); - return null; - } - final TokensResponseModel igcTextData = await TokensRepo.tokenize(accessToken, req); @@ -201,15 +192,8 @@ class MessageDataController extends BaseController { ); try { - final String? accessToken = + final String accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in _getPangeaRepresentation", - s: StackTrace.current, - ); - return null; - } final FullTextTranslationResponseModel res = await FullTextTranslationRepo.translate( diff --git a/lib/pangea/controllers/speech_to_text_controller.dart b/lib/pangea/controllers/speech_to_text_controller.dart index 3daeada07..1b151aca0 100644 --- a/lib/pangea/controllers/speech_to_text_controller.dart +++ b/lib/pangea/controllers/speech_to_text_controller.dart @@ -52,15 +52,8 @@ class SpeechToTextController { if (_cache.containsKey(cacheKey)) { return _cache[cacheKey]!.data; } else { - final String? accessToken = + final String accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: 'null accessToken in speech to text controller', - s: StackTrace.current, - ); - return null; - } final Future response = _fetchResponse( accessToken: accessToken, diff --git a/lib/pangea/controllers/text_to_speech_controller.dart b/lib/pangea/controllers/text_to_speech_controller.dart index b00fa23a4..25b888e05 100644 --- a/lib/pangea/controllers/text_to_speech_controller.dart +++ b/lib/pangea/controllers/text_to_speech_controller.dart @@ -6,7 +6,6 @@ import 'package:fluffychat/pangea/config/environment.dart'; import 'package:fluffychat/pangea/constants/model_keys.dart'; import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; import 'package:fluffychat/pangea/network/urls.dart'; -import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:http/http.dart'; import '../network/requests.dart'; @@ -100,15 +99,8 @@ class TextToSpeechController { if (_cache.containsKey(params)) { return _cache[params]!.data; } else { - final String? accessToken = + final String accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in text to speech controller", - s: StackTrace.current, - ); - return null; - } final Future response = _fetchResponse( accessToken, params, diff --git a/lib/pangea/controllers/user_controller.dart b/lib/pangea/controllers/user_controller.dart index 541371e34..a4fd08c4d 100644 --- a/lib/pangea/controllers/user_controller.dart +++ b/lib/pangea/controllers/user_controller.dart @@ -222,8 +222,6 @@ class UserController extends BaseController { /// The [interests] parameter is a list of new interests for the user. /// The [speaks] parameter is a list of new languages the user speaks. /// The [publicProfile] parameter indicates whether the user's profile should be public or not. - /// - /// Throws an error if [userModel] or [accessToken] is null. Future updateUserProfile({ String? dateOfBirth, String? targetLanguage, @@ -233,10 +231,9 @@ class UserController extends BaseController { List? speaks, bool? publicProfile, }) async { - final String? accessToken = await this.accessToken; - if (userModel == null || accessToken == null) { + if (userModel == null) { ErrorHandler.logError( - e: "calling updateUserProfile with userModel == null or accessToken == null", + e: "calling updateUserProfile with userModel == null", ); return; } @@ -267,11 +264,11 @@ class UserController extends BaseController { final Profile updatedUserProfile = await PUserRepo.updateUserProfile( Profile.fromJson(profileJson), - accessToken, + await accessToken, ); PUserModel( - access: accessToken, + access: await accessToken, refresh: userModel!.refresh, profile: updatedUserProfile, ).save(_pangeaController); @@ -295,19 +292,17 @@ class UserController extends BaseController { /// /// If the locally stored user model is null or the access token has /// expired, it fetches the user model. - /// If the user model is still null after fetching, an error is logged. + /// If the user model is still null after fetching, an error thrown. /// /// Returns the access token as a string, or null if the user model is null. - Future get accessToken async { + Future get accessToken async { final PUserModel? useThisOne = needNewJWT ? await fetchUserModel() : userModel; if (useThisOne == null) { - ErrorHandler.logError( - e: "trying to get accessToken with userModel = null", - ); + throw ("Trying to get accessToken with null userModel"); } - return useThisOne?.access; + return useThisOne.access; } /// Returns the full name of the user. diff --git a/lib/pangea/controllers/word_net_controller.dart b/lib/pangea/controllers/word_net_controller.dart index 43d1a66b0..18c3290a9 100644 --- a/lib/pangea/controllers/word_net_controller.dart +++ b/lib/pangea/controllers/word_net_controller.dart @@ -1,7 +1,6 @@ import 'package:collection/collection.dart'; import 'package:fluffychat/pangea/constants/language_constants.dart'; import 'package:fluffychat/pangea/repo/word_repo.dart'; -import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:http/http.dart' as http; import '../models/word_data_model.dart'; @@ -54,16 +53,8 @@ class WordController extends BaseController { if (local != null) return local; - final String? accessToken = + final String accessToken = await _pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in word controller", - s: StackTrace.current, - ); - return null; - } - final WordData remote = await WordRepo.getWordNetData( accessToken: accessToken, fullText: fullText, diff --git a/lib/pangea/pages/find_partner/find_partner.dart b/lib/pangea/pages/find_partner/find_partner.dart index 44274a608..46eb365ae 100644 --- a/lib/pangea/pages/find_partner/find_partner.dart +++ b/lib/pangea/pages/find_partner/find_partner.dart @@ -5,6 +5,7 @@ import 'package:fluffychat/pangea/models/language_model.dart'; import 'package:fluffychat/pangea/models/user_model.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; import '../../../widgets/matrix.dart'; import '../../controllers/pangea_controller.dart'; @@ -39,6 +40,7 @@ class FindPartnerController extends State { final List _userProfilesCache = []; final scrollController = ScrollController(); + String? error; @override void initState() { @@ -67,6 +69,17 @@ class FindPartnerController extends State { @override Widget build(BuildContext context) { + if (error != null && error!.isNotEmpty) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(L10n.of(context)!.oopsSomethingWentWrong), + Text(L10n.of(context)!.errorPleaseRefresh), + ], + ), + ); + } return FindPartnerView(this); } @@ -92,26 +105,25 @@ class FindPartnerController extends State { if (loading || nextUrl == null) return; setState(() => loading = true); - final String? accessToken = - await pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in find partner controller", - s: StackTrace.current, + UserProfileSearchResponse response; + try { + final String accessToken = + await pangeaController.userController.accessToken; + response = await PUserRepo.searchUserProfiles( + accessToken: accessToken, + targetLanguage: targetLanguageSearch.langCode, + sourceLanguage: sourceLanguageSearch.langCode, + country: countrySearch, + limit: 15, + pageNumber: nextPage.toString(), ); + } catch (err, s) { + error = err.toString(); + setState(() => loading = false); + ErrorHandler.logError(e: err, s: s); return; } - final UserProfileSearchResponse response = - await PUserRepo.searchUserProfiles( - accessToken: accessToken, - targetLanguage: targetLanguageSearch.langCode, - sourceLanguage: sourceLanguageSearch.langCode, - country: countrySearch, - limit: 15, - pageNumber: nextPage.toString(), - ); - nextUrl = response.next; nextPage++; diff --git a/lib/pangea/repo/span_data_repo.dart b/lib/pangea/repo/span_data_repo.dart index 3c2eb2ab3..cc5c0640a 100644 --- a/lib/pangea/repo/span_data_repo.dart +++ b/lib/pangea/repo/span_data_repo.dart @@ -13,7 +13,7 @@ import '../network/urls.dart'; class SpanDataRepo { static Future getSpanDetails( - String? accessToken, { + String accessToken, { required SpanDetailsRepoReqAndRes request, }) async { final Requests req = Requests( diff --git a/lib/pangea/repo/topic_data_repo.dart b/lib/pangea/repo/topic_data_repo.dart index 9a5def03f..7a4ce049f 100644 --- a/lib/pangea/repo/topic_data_repo.dart +++ b/lib/pangea/repo/topic_data_repo.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:flutter/services.dart'; - import 'package:http/http.dart'; import '../config/environment.dart'; @@ -12,7 +11,7 @@ import '../network/urls.dart'; /// accepts ChatTopic and calls an API for a list of Lemma class TopicDataRepo { static Future generate( - String? accessToken, { + String accessToken, { required TopicDataRequest request, }) async { final Requests req = Requests( diff --git a/lib/pangea/widgets/chat/message_audio_card.dart b/lib/pangea/widgets/chat/message_audio_card.dart index 5c1f8e67b..cfae4282a 100644 --- a/lib/pangea/widgets/chat/message_audio_card.dart +++ b/lib/pangea/widgets/chat/message_audio_card.dart @@ -46,7 +46,6 @@ class MessageAudioCardState extends State { await widget.messageEvent.getMatrixAudioFile(langCode, context); if (mounted) setState(() => _isLoading = false); } catch (e, _) { - debugPrint(StackTrace.current.toString()); if (!mounted) return; setState(() => _isLoading = false); ScaffoldMessenger.of(context).showSnackBar( diff --git a/lib/pangea/widgets/chat/message_translation_card.dart b/lib/pangea/widgets/chat/message_translation_card.dart index 9ee15faf7..fd80df134 100644 --- a/lib/pangea/widgets/chat/message_translation_card.dart +++ b/lib/pangea/widgets/chat/message_translation_card.dart @@ -58,17 +58,9 @@ class MessageTranslationCardState extends State { } oldSelectedText = widget.selection.selectedText; - final String? accessToken = + final String accessToken = await MatrixState.pangeaController.userController.accessToken; - if (accessToken == null) { - ErrorHandler.logError( - e: "null accessToken in translateSelection", - s: StackTrace.current, - ); - return; - } - final resp = await FullTextTranslationRepo.translate( accessToken: accessToken, request: FullTextTranslationRequestModel(