66import android .preference .Preference ;
77import android .preference .PreferenceFragment ;
88import android .text .InputType ;
9+ import android .text .TextUtils ;
910import android .view .LayoutInflater ;
1011import android .view .MenuItem ;
1112import 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