Java Code Examples for io.particle.android.sdk.cloud.exceptions.ParticleCloudException#getResponseData()

The following examples show how to use io.particle.android.sdk.cloud.exceptions.ParticleCloudException#getResponseData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetReadyActivity.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void onGenerateClaimCodeFail(@NonNull ParticleCloudException error) {
    log.d("Generating claim code failed");
    ParticleCloudException.ResponseErrorData errorData = error.getResponseData();
    if (errorData != null && errorData.getHttpStatusCode() == 401) {
        onUnauthorizedError();
    } else {
        if (isFinishing()) {
            return;
        }
        String errorMsg = getString(R.string.get_ready_could_not_connect_to_cloud);
        if (error.getMessage() != null) {
            errorMsg = errorMsg + "\n\n" + error.getMessage();
        }
        new AlertDialog.Builder(GetReadyActivity.this)
                .setTitle(R.string.error)
                .setMessage(errorMsg)
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                .show();
    }
}
 
Example 2
Source File: GetReadyActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void onGenerateClaimCodeFail(@NonNull ParticleCloudException error) {
    log.d("Generating claim code failed");
    ParticleCloudException.ResponseErrorData errorData = error.getResponseData();
    if (errorData != null && errorData.getHttpStatusCode() == 401) {
        onUnauthorizedError();
    } else {
        if (isFinishing()) {
            return;
        }

        // FIXME: we could just check the internet connection here ourselves...
        String errorMsg = getString(R.string.get_ready_could_not_connect_to_cloud);
        if (error.getMessage() != null) {
            errorMsg = errorMsg + "\n\n" + error.getMessage();
        }
        new AlertDialog.Builder(GetReadyActivity.this)
                .setTitle(R.string.error)
                .setMessage(errorMsg)
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                .show();
    }
}
 
Example 3
Source File: CreateAccountActivity.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private void signUpTaskFailure(@NonNull ParticleCloudException error) {
    log.d("onFailed()");
    ParticleUi.showParticleButtonProgress(CreateAccountActivity.this,
            R.id.action_create_account, false);

    String msg = getString(R.string.create_account_unknown_error);
    if (error.getKind() == ParticleCloudException.Kind.NETWORK) {
        msg = getString(R.string.create_account_error_communicating_with_server);

    } else if (error.getResponseData() != null) {

        if (error.getResponseData().getHttpStatusCode() == 401
                && (getResources().getBoolean(R.bool.organization) ||
                getResources().getBoolean(R.bool.productMode))) {
            msg = getString(R.string.create_account_account_already_exists_for_email_address);
        } else {
            msg = error.getServerErrorMsg();
        }
    }
    //TODO remove once sign up error code is fixed
    if (error.getCause() != null && error.getCause().getMessage().contains(emailView.getText().toString())) {
        msg = getString(R.string.create_account_account_already_exists_for_email_address);
    }

    Toaster.l(CreateAccountActivity.this, msg, Gravity.CENTER_VERTICAL);
    emailView.requestFocus();
}
 
Example 4
Source File: CreateAccountActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void signUpTaskFailure(@NonNull ParticleCloudException error) {
    // FIXME: look at old Spark app for what we do here UI & workflow-wise
    log.d("onFailed()");
    ParticleUi.showParticleButtonProgress(CreateAccountActivity.this,
            R.id.action_create_account, false);

    String msg = getString(R.string.create_account_unknown_error);
    if (error.getKind() == ParticleCloudException.Kind.NETWORK) {
        msg = getString(R.string.create_account_error_communicating_with_server);

    } else if (error.getResponseData() != null) {

        if (error.getResponseData().getHttpStatusCode() == 401
                && (getResources().getBoolean(R.bool.organization) ||
                getResources().getBoolean(R.bool.productMode))) {
            msg = getString(R.string.create_account_account_already_exists_for_email_address);
        } else {
            msg = error.getServerErrorMsg();
        }
    }
    //TODO remove once sign up error code is fixed
    if (error.getCause() != null && error.getCause().getMessage().contains(emailView.getText().toString())) {
        msg = getString(R.string.create_account_account_already_exists_for_email_address);
    }

    Toaster.l(CreateAccountActivity.this, msg, Gravity.CENTER_VERTICAL);
    emailView.requestFocus();
}