Search in sources :

Example 1 with UnknownErrorException

use of com.nextcloud.android.sso.exceptions.UnknownErrorException in project nextcloud-notes by stefan-niedermann.

the class TipsAdapter method setThrowables.

public void setThrowables(@NonNull List<Throwable> throwables) {
    for (final var throwable : throwables) {
        if (throwable instanceof TokenMismatchException) {
            add(R.string.error_dialog_tip_token_mismatch_retry);
            add(R.string.error_dialog_tip_token_mismatch_clear_storage);
            final var intent = new Intent(ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID)).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_deck_info);
            add(R.string.error_dialog_tip_clear_storage, intent);
        } else if (throwable instanceof NextcloudFilesAppNotSupportedException) {
            add(R.string.error_dialog_tip_files_outdated);
        } else if (throwable instanceof NextcloudApiNotRespondingException) {
            if (VERSION.SDK_INT >= VERSION_CODES.M) {
                add(R.string.error_dialog_tip_disable_battery_optimizations, new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_battery_settings));
            } else {
                add(R.string.error_dialog_tip_disable_battery_optimizations);
            }
            add(R.string.error_dialog_tip_files_force_stop);
            add(R.string.error_dialog_tip_files_delete_storage);
            final var intent = new Intent(ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID)).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_deck_info);
            add(R.string.error_dialog_tip_clear_storage, intent);
        } else if (throwable instanceof SocketTimeoutException || throwable instanceof ConnectException) {
            add(R.string.error_dialog_timeout_instance);
            add(R.string.error_dialog_timeout_toggle, new Intent(Settings.ACTION_WIFI_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_network));
        } else if (throwable instanceof JSONException || throwable instanceof NullPointerException) {
            add(R.string.error_dialog_check_server);
        } else if (throwable instanceof NextcloudHttpRequestFailedException) {
            final int statusCode = ((NextcloudHttpRequestFailedException) throwable).getStatusCode();
            switch(statusCode) {
                case 302:
                    add(R.string.error_dialog_server_app_enabled);
                    add(R.string.error_dialog_redirect);
                    break;
                case 500:
                    add(R.string.error_dialog_check_server_logs);
                    break;
                case 503:
                    add(R.string.error_dialog_check_maintenance);
                    break;
                case 507:
                    add(R.string.error_dialog_insufficient_storage);
                    break;
            }
        } else if (throwable instanceof UnknownErrorException) {
            if ("com.nextcloud.android.sso.QueryParam".equals(throwable.getMessage())) {
                add(R.string.error_dialog_min_version, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.nextcloud.client")).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_update_files_app));
            }
        }
    }
    notifyDataSetChanged();
}
Also used : TokenMismatchException(com.nextcloud.android.sso.exceptions.TokenMismatchException) SocketTimeoutException(java.net.SocketTimeoutException) UnknownErrorException(com.nextcloud.android.sso.exceptions.UnknownErrorException) NextcloudApiNotRespondingException(com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException) JSONException(org.json.JSONException) Intent(android.content.Intent) NextcloudFilesAppNotSupportedException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException) ConnectException(java.net.ConnectException)

Example 2 with UnknownErrorException

use of com.nextcloud.android.sso.exceptions.UnknownErrorException in project nextcloud-notes by stefan-niedermann.

the class MainViewModelTest method containsNonInfrastructureRelatedItems.

@Test
public void containsNonInfrastructureRelatedItems() {
    // noinspection ConstantConditions
    final var vm = new MainViewModel(ApplicationProvider.getApplicationContext(), null);
    assertFalse(vm.containsNonInfrastructureRelatedItems(null));
    assertFalse(vm.containsNonInfrastructureRelatedItems(Collections.emptyList()));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new UnknownErrorException("Software caused connection abort"))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new UnknownErrorException("failed to connect to example.com (port 443) from /:: (port 39885) after 5000ms: connect failed: ENETUNREACH (Network is unreachable)"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new UnknownErrorException("Foo bar"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"), new UnknownErrorException("Software caused connection abort"))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("Software caused connection abort"))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("failed to connect to example.com (port 443) from /:: (port 39885) after 5000ms: connect failed: ENETUNREACH (Network is unreachable)"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("Foo bar"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"), new RuntimeException("Software caused connection abort"))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException(new UnknownErrorException("Software caused connection abort")))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException(new UnknownErrorException("failed to connect to example.com (port 443) from /:: (port 39885) after 5000ms: connect failed: ENETUNREACH (Network is unreachable)")))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException(new UnknownErrorException("Foo bar")))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"), new RuntimeException(new UnknownErrorException("Software caused connection abort")))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("Foo", new UnknownErrorException("Software caused connection abort")))));
    assertFalse(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("Foo", new UnknownErrorException("failed to connect to example.com (port 443) from /:: (port 39885) after 5000ms: connect failed: ENETUNREACH (Network is unreachable)")))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("Foo", new UnknownErrorException("Foo bar")))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new Exception("Software caused connection abort"), new RuntimeException("Foo", new UnknownErrorException("Software caused connection abort")))));
    assertTrue(vm.containsNonInfrastructureRelatedItems(List.of(new RuntimeException("Foo", new Exception("Software caused connection abort")))));
}
Also used : UnknownErrorException(com.nextcloud.android.sso.exceptions.UnknownErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnknownErrorException(com.nextcloud.android.sso.exceptions.UnknownErrorException) Test(org.junit.Test)

Aggregations

UnknownErrorException (com.nextcloud.android.sso.exceptions.UnknownErrorException)2 Intent (android.content.Intent)1 NextcloudApiNotRespondingException (com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException)1 NextcloudFilesAppNotSupportedException (com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException)1 NextcloudHttpRequestFailedException (com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException)1 TokenMismatchException (com.nextcloud.android.sso.exceptions.TokenMismatchException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 JSONException (org.json.JSONException)1 Test (org.junit.Test)1