Skip to content

Commit

Permalink
#1148 | Show user friendly error message when fast sync is incompatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsanadi6 committed Nov 29, 2024
1 parent 7d2c1ba commit a3093a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/openchs-android/config/beforeSyncMessages.en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"syncError": "Sync Failed",
"tryAgain": "Try Again",
"tryAgain": "Try Again/पुनः प्रयास करें",
"cancel": "Cancel",
"settings": "Settings",
"syncData": "Sync Data",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions packages/openchs-android/src/framework/errorHandling/AvniError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/openchs-android/src/views/LoginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a3093a8

Please sign in to comment.