diff options
author | cyBerta <cyberta@riseup.net> | 2024-10-26 04:52:57 +0200 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2024-12-11 00:09:34 +0000 |
commit | be1751f1537e44463c2d031eaac3977e0152c5bf (patch) | |
tree | b2613c2597cb047ca4722d1bb55601f89ca3cb29 /app | |
parent | 6c1b8f8c0ed8915de7247a603481e4e434ebd6da (diff) |
fix error handling when setting up a new provider
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java index e39f3bd7..8ae5bfea 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java @@ -15,6 +15,7 @@ import static se.leap.bitmaskclient.providersetup.ProviderAPI.DELAY; import static se.leap.bitmaskclient.providersetup.ProviderAPI.ERRORS; import static se.leap.bitmaskclient.providersetup.ProviderAPI.MISSING_NETWORK_CONNECTION; import static se.leap.bitmaskclient.providersetup.ProviderAPI.PARAMETERS; +import static se.leap.bitmaskclient.providersetup.ProviderAPI.PROVIDER_NOK; import static se.leap.bitmaskclient.providersetup.ProviderAPI.RECEIVER_KEY; import static se.leap.bitmaskclient.providersetup.ProviderAPI.TOR_EXCEPTION; import static se.leap.bitmaskclient.providersetup.ProviderAPI.TOR_TIMEOUT; @@ -124,30 +125,31 @@ public class ProviderApiManager extends ProviderApiManagerBase { if (!provider.hasDefinition()) { - downloadProviderDefinition(provider); + downloadProviderDefinition(result, provider); + if (result.containsKey(ERRORS)) { + eventSender.sendToReceiverOrBroadcast(receiver, PROVIDER_NOK, result, provider); + return; + } } IProviderApiManager apiManager = versionedApiFactory.getProviderApiManager(provider); apiManager.handleAction(action, provider, parameters, receiver); } - private void downloadProviderDefinition(Provider provider) { + private void downloadProviderDefinition(Bundle result, Provider provider) { getPersistedProviderUpdates(provider); if (provider.hasDefinition()) { return; } - getAndSetProviderJson(provider); + getAndSetProviderJson(result, provider); } - private Bundle getAndSetProviderJson(Provider provider) { - Bundle result = new Bundle(); - + private Bundle getAndSetProviderJson(Bundle result, Provider provider) { String providerJsonUrl = provider.getMainUrl() + "/provider.json"; String providerDotJsonString = fetch(providerJsonUrl, true); if (ConfigHelper.checkErroneousDownload(providerDotJsonString) || !isValidJson(providerDotJsonString)) { - eventSender.setErrorResult(result, malformed_url, null); - return result; + return eventSender.setErrorResult(result, malformed_url, null); } if (DEBUG_MODE) { @@ -163,7 +165,7 @@ public class ProviderApiManager extends ProviderApiManagerBase { } } catch (JSONException e) { - eventSender.setErrorResult(result, providerDotJsonString); + return eventSender.setErrorResult(result, providerDotJsonString); } return result; } |