Skip to content

Commit 2d2bcae

Browse files
authored
Merge pull request #10010 from wordpress-mobile/issue/9384-change-email-error
Improve error messaging when changing account settings
2 parents 86b0db4 + 44cf004 commit 2d2bcae

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsFragment.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.preference.Preference;
77
import android.preference.PreferenceFragment;
88
import android.text.InputType;
9+
import android.text.TextUtils;
910
import android.view.LayoutInflater;
1011
import android.view.MenuItem;
1112
import android.view.View;
@@ -285,7 +286,13 @@ public void onAccountChanged(OnAccountChanged event) {
285286
showChangePasswordProgressDialog(false);
286287

287288
if (event.isError()) {
288-
ToastUtils.showToast(getActivity(), event.error.message, ToastUtils.Duration.LONG);
289+
// We usually rely on event.error.type and provide our own localized message.
290+
// This case is exceptional because:
291+
// 1. The server-side error type is generic, but patching this server-side is quite involved
292+
// 2. We know the error string return from the server has decent localization
293+
String errorMessage = !TextUtils.isEmpty(event.error.message) ? event.error.message
294+
: getString(R.string.error_post_account_settings);
295+
ToastUtils.showToast(getActivity(), errorMessage, ToastUtils.Duration.LONG);
289296
AppLog.e(T.SETTINGS, event.error.message);
290297
} else {
291298
ToastUtils.showToast(getActivity(), R.string.change_password_confirmation, ToastUtils.Duration.LONG);
@@ -299,8 +306,13 @@ public void onAccountChanged(OnAccountChanged event) {
299306
ToastUtils.Duration.LONG);
300307
break;
301308
case SETTINGS_POST_ERROR:
302-
ToastUtils.showToast(getActivity(), R.string.error_post_account_settings,
303-
ToastUtils.Duration.LONG);
309+
// We usually rely on event.error.type and provide our own localized message.
310+
// This case is exceptional because:
311+
// 1. The server-side error type is generic, but patching this server-side is quite involved
312+
// 2. We know the error string return from the server has decent localization
313+
String errorMessage = !TextUtils.isEmpty(event.error.message) ? event.error.message
314+
: getString(R.string.error_post_account_settings);
315+
ToastUtils.showToast(getActivity(), errorMessage, ToastUtils.Duration.LONG);
304316
// we optimistically show the email change snackbar, if that request fails, we should
305317
// remove the snackbar
306318
checkIfEmailChangeIsPending();

0 commit comments

Comments
 (0)