From a3093a813f1a26c87aa2f62627380618a3829cea Mon Sep 17 00:00:00 2001 From: ADAM M SANADI Date: Fri, 29 Nov 2024 16:49:32 +0530 Subject: [PATCH] #1148 | Show user friendly error message when fast sync is incompatible. --- .../config/beforeSyncMessages.en.json | 7 ++++--- .../src/framework/errorHandling/AvniError.js | 14 ++++++++++++++ packages/openchs-android/src/views/LoginView.js | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/openchs-android/config/beforeSyncMessages.en.json b/packages/openchs-android/config/beforeSyncMessages.en.json index 6dbd9803c..2356df7a0 100644 --- a/packages/openchs-android/config/beforeSyncMessages.en.json +++ b/packages/openchs-android/config/beforeSyncMessages.en.json @@ -1,6 +1,6 @@ { "syncError": "Sync Failed", - "tryAgain": "Try Again", + "tryAgain": "Try Again/पुनः प्रयास करें", "cancel": "Cancel", "settings": "Settings", "syncData": "Sync Data", @@ -42,9 +42,10 @@ "restoringDb": "Restoring database", "restoreComplete": "Restore complete", "restoreFailed": "Restore failed, will sync from server", - "restoreFailedTitle": "Fast sync failed", + "restoreFailedTitle": "Fast sync failed/तेज़ सिंक फ़ेल", "restoreNoDump": "No dump present, will sync fully from server", - "performNormalSync": "Perform slow sync", + "performNormalSync": "Perform slow sync/धीमा सिंक करें", + "copyErrorTryAgain": "Copy Error & Try Again", "NoCatchmentFoundErrorMessage": "No catchment found for the user, please contact administrator.", "FetchingChangedResource": "Fetching changed resources from the server", "goToSummary": "SUMMARY", diff --git a/packages/openchs-android/src/framework/errorHandling/AvniError.js b/packages/openchs-android/src/framework/errorHandling/AvniError.js index 2d1bd6311..3a999cd11 100644 --- a/packages/openchs-android/src/framework/errorHandling/AvniError.js +++ b/packages/openchs-android/src/framework/errorHandling/AvniError.js @@ -15,6 +15,20 @@ class AvniError { } static createFromUserMessageAndStackTrace(userMessage, stackTraceString) { + const regexToUserMessageMap = [ + { + regex: /.*(Provided schema version \d+ is less than last set)/i, + userMessage: "Update the app to continue fast sync or click on 'perform slow sync'/तेज़ सिंक जारी रखने के लिए ऐप को अपडेट करें, या 'धीमा सिंक करें' पर क्लिक करें।" + } + ]; + + for (const { regex, userMessage: replacementMessage } of regexToUserMessageMap) { + if (regex.test(userMessage)) { + userMessage = replacementMessage; + return AvniError.create(userMessage, `${userMessage}\n${stackTraceString}`, true); + } + } + return AvniError.create(userMessage, `${userMessage}\n${stackTraceString}`); } diff --git a/packages/openchs-android/src/views/LoginView.js b/packages/openchs-android/src/views/LoginView.js index 84527af96..cedf5b697 100644 --- a/packages/openchs-android/src/views/LoginView.js +++ b/packages/openchs-android/src/views/LoginView.js @@ -168,7 +168,7 @@ class LoginView extends AbstractComponent { }) }, { - text: "copyErrorTryAgain", + text: this.I18n.t("copyErrorTryAgain"), onPress: () => { General.logDebug("LoginView", avniError.reportingText); Clipboard.setString(avniError.reportingText); @@ -189,7 +189,7 @@ class LoginView extends AbstractComponent { } restoreFailureAlert(error, source) { - if (error instanceof ServerError) + if (error && error instanceof ServerError) getAvniError(error, this.I18n).then((avniError) => this.displayFailureAlert(avniError, source)); else { this.displayFailureAlert(ErrorUtil.getAvniErrorSync(error), source);