@Test public void shouldGetErrorMessageRootCause() throws Exception { RuntimeException exception = new RuntimeException("foo", new IOException("bar")); BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, exception); assertThat(state.getErrorMessage(resources)).isEqualTo("foo"); assertThat(state.getDetailedErrorMessage(resources)).isEqualTo("foo (exception: java.lang.RuntimeException: foo, underlying=java.io.IOException: bar)"); }
@Test public void shouldGetErrorMessage() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new IOException("foo")); assertThat(state.getErrorMessage(resources)).isEqualTo("foo"); assertThat(state.getDetailedErrorMessage(resources)).isEqualTo("foo (exception: java.io.IOException: foo)"); }
@Test public void shouldGetErrorMessagePrefix() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new MessagingException("Unable to get IMAP prefix")); assertThat(state.getErrorMessage(resources)).isEqualTo("Temporary Gmail IMAP error, try again later."); }
@Test public void shouldGetErrorMessageRequiresWifi() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new RequiresWifiException()); assertThat(state.getErrorMessage(resources)).isEqualTo("No Wifi connection"); }
private void handleErrorState(BackupState state) { if (state.isAuthException()) { appLog(R.string.app_log_backup_failed_authentication, state.getDetailedErrorMessage(getResources())); if (shouldNotifyUser(state)) { notifyUser(NOTIFICATION_ID_WARNING, notificationBuilder(stat_sys_warning, getString(R.string.notification_auth_failure), getString(getAuthPreferences().useXOAuth() ? R.string.status_auth_failure_details_xoauth : R.string.status_auth_failure_details_plain))); } } else if (state.isConnectivityError()) { appLog(R.string.app_log_backup_failed_connectivity, state.getDetailedErrorMessage(getResources())); } else if (state.isPermissionException()) { if (state.backupType != MANUAL) { Bundle extras = new Bundle(); extras.putStringArray(MainActivity.EXTRA_PERMISSIONS, state.getMissingPermissions()); notifyUser(NOTIFICATION_ID_WARNING, notificationBuilder(R.drawable.ic_notification, getString(R.string.notification_missing_permission), formatMissingPermissionDetails(getResources(), state.getMissingPermissions())) .setContentIntent(getPendingIntent(extras))); } } else { appLog(R.string.app_log_backup_failed_general_error, state.getDetailedErrorMessage(getResources())); if (shouldNotifyUser(state)) { notifyUser(NOTIFICATION_ID_WARNING, notificationBuilder(stat_sys_warning, getString(R.string.notification_general_error), state.getErrorMessage(getResources()))); } } }