From a8071c3532497edfca2a2020f42b0d4cf37f1bb1 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 9 Apr 2026 13:53:25 +0200 Subject: [PATCH] Catch any errors that might happen when calling handleUpdateExerciseFromApi This seems to mostly happen when the app is running (or is moved) to the background --- lib/providers/exercises.dart | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/providers/exercises.dart b/lib/providers/exercises.dart index 975147f8b..bf0889b2d 100644 --- a/lib/providers/exercises.dart +++ b/lib/providers/exercises.dart @@ -314,14 +314,21 @@ class ExercisesProvider with ChangeNotifier { // Note: no await since we don't care for the updated data right now. It // will be written to the db whenever the request finishes and we will get // the updated exercise the next time - handleUpdateExerciseFromApi(database, exerciseId).then( - (_) {}, - onError: (error, stackTrace) => _logger.info( - 'Error while calling unawaited handleUpdateExerciseFromApi', - error, - stackTrace, - ), - ); + try { + handleUpdateExerciseFromApi(database, exerciseId).then( + (_) {}, + onError: (error, stackTrace) => _logger.info( + 'Error while calling unawaited handleUpdateExerciseFromApi', + error, + stackTrace, + ), + ); + } catch (e) { + // This is here just to catch any errors that seem to happen when the app is running + // in the background: https://github.com/wger-project/wger/issues/2206 + + _logger.info('Error while calling handleUpdateExerciseFromApi:', e); + } return exercise; } on NoSuchEntryException {