summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2018-02-18 15:14:18 +0100
committercyBerta <cyberta@riseup.net>2018-02-18 15:14:18 +0100
commit6815c6521e633fa3798c7ef37b405bdb60fa1ff5 (patch)
tree125244710aba4c586e6b97f8ed4b72a2ed7f4a30 /app/src/main/java/se/leap/bitmaskclient
parent7375bc9e5e54ad9d6632eb112ed8129ed9f6ec49 (diff)
#8852 improve signup error handling for backend error messages
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java19
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java2
3 files changed, 19 insertions, 4 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
index 2e153c7a..f5efde05 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -49,6 +49,8 @@ public class ProviderAPI extends IntentService implements ProviderApiManagerBase
RECEIVER_KEY = "receiver",
ERRORS = "errors",
ERRORID = "errorId",
+ BACKEND_ERROR_KEY = "error",
+ BACKEND_ERROR_MESSAGE = "message",
DOWNLOAD_SERVICE_JSON = "ProviderAPI.DOWNLOAD_SERVICE_JSON",
PROVIDER_SET_UP = "ProviderAPI.PROVIDER_SET_UP";
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
index fc370f81..76275d9d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
@@ -61,6 +61,8 @@ import static se.leap.bitmaskclient.Constants.CREDENTIALS_USERNAME;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.PROVIDER_PRIVATE_KEY;
import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
+import static se.leap.bitmaskclient.ProviderAPI.BACKEND_ERROR_KEY;
+import static se.leap.bitmaskclient.ProviderAPI.BACKEND_ERROR_MESSAGE;
import static se.leap.bitmaskclient.ProviderSetupFailedDialog.DOWNLOAD_ERRORS.ERROR_CERTIFICATE_PINNING;
import static se.leap.bitmaskclient.ProviderSetupFailedDialog.DOWNLOAD_ERRORS.ERROR_CORRUPTED_PROVIDER_JSON;
import static se.leap.bitmaskclient.ProviderSetupFailedDialog.DOWNLOAD_ERRORS.ERROR_INVALID_CERTIFICATE;
@@ -89,6 +91,7 @@ import static se.leap.bitmaskclient.ProviderAPI.SUCCESSFUL_LOGOUT;
import static se.leap.bitmaskclient.ProviderAPI.SUCCESSFUL_SIGNUP;
import static se.leap.bitmaskclient.ProviderAPI.UPDATE_PROVIDER_DETAILS;
import static se.leap.bitmaskclient.R.string.certificate_error;
+import static se.leap.bitmaskclient.R.string.switch_provider_menu_option;
import static se.leap.bitmaskclient.R.string.vpn_certificate_is_invalid;
import static se.leap.bitmaskclient.R.string.error_io_exception_user_message;
import static se.leap.bitmaskclient.R.string.error_json_exception_user_message;
@@ -298,7 +301,7 @@ public abstract class ProviderApiManagerBase {
JSONObject api_result = sendNewUserDataToSRPServer(provider.getApiUrlString(), username, new BigInteger(1, salt).toString(16), password_verifier.toString(16), okHttpClient);
Bundle result = new Bundle();
- if (api_result.has(ERRORS))
+ if (api_result.has(ERRORS) || api_result.has(BACKEND_ERROR_KEY))
result = authFailedNotification(api_result, username);
else {
result.putString(CREDENTIALS_USERNAME, username);
@@ -390,8 +393,8 @@ public abstract class ProviderApiManagerBase {
private Bundle authFailedNotification(JSONObject result, String username) {
Bundle userNotificationBundle = new Bundle();
- Object baseErrorMessage = result.opt(ERRORS);
- if (baseErrorMessage != null) {
+ if (result.has(ERRORS)) {
+ Object baseErrorMessage = result.opt(ERRORS);
if (baseErrorMessage instanceof JSONObject) {
try {
JSONObject errorMessage = result.getJSONObject(ERRORS);
@@ -409,6 +412,16 @@ public abstract class ProviderApiManagerBase {
e.printStackTrace();
}
}
+ } else if (result.has(BACKEND_ERROR_KEY)) {
+ try {
+ String backendErrorMessage = resources.getString(R.string.error_json_exception_user_message);
+ if (result.has(BACKEND_ERROR_MESSAGE)) {
+ backendErrorMessage = resources.getString(R.string.error) + result.getString(BACKEND_ERROR_MESSAGE);
+ }
+ userNotificationBundle.putString(resources.getString(R.string.user_message), backendErrorMessage);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
}
if (!username.isEmpty())
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
index 6faf8bb8..d41be512 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
@@ -360,7 +360,7 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
Linkify.addLinks(userMessage, Linkify.ALL);
userMessage.setMovementMethod(LinkMovementMethod.getInstance());
userMessage.setVisibility(VISIBLE);
- } else if (userMessage.getVisibility() != VISIBLE) {
+ } else if (userMessage.getVisibility() != GONE) {
userMessage.setVisibility(GONE);
}