add payment required error

This commit is contained in:
Daniel Gultsch 2016-08-16 10:39:59 +02:00 committed by Christian Schneppe
parent bbf6348187
commit da1edafd49
3 changed files with 21 additions and 2 deletions

View file

@ -110,7 +110,8 @@ public class Account extends AbstractEntity {
REGISTRATION_PLEASE_WAIT(true),
STREAM_ERROR(true),
POLICY_VIOLATION(true),
REGISTRATION_PASSWORD_TOO_WEAK(true);
REGISTRATION_PASSWORD_TOO_WEAK(true),
PAYMENT_REQUIRED(true);
private final boolean isError;
@ -168,6 +169,8 @@ public class Account extends AbstractEntity {
return R.string.registration_password_too_weak;
case STREAM_ERROR:
return R.string.account_status_stream_error;
case PAYMENT_REQUIRED:
return R.string.payment_required;
default:
return R.string.account_status_unknown;
}

View file

@ -397,6 +397,8 @@ public class XmppConnection implements Runnable {
this.changeStatus(Account.State.SECURITY_ERROR);
} catch (final UnauthorizedException e) {
this.changeStatus(Account.State.UNAUTHORIZED);
} catch (final PaymentRequiredException e) {
this.changeStatus(Account.State.PAYMENT_REQUIRED);
} catch (final UnknownHostException | ConnectException e) {
this.changeStatus(Account.State.SERVER_NOT_FOUND);
} catch (final SocksSocketFactory.SocksProxyNotFoundException e) {
@ -518,7 +520,16 @@ public class XmppConnection implements Runnable {
}
break;
} else if (nextTag.isStart("failure")) {
throw new UnauthorizedException();
final Element failure = tagReader.readElement(nextTag);
final String accountDisabled = failure.findChildContent("account-disabled");
if (accountDisabled != null
&& accountDisabled.contains("renew")
&& Config.MAGIC_CREATE_DOMAIN != null
&& accountDisabled.contains(Config.MAGIC_CREATE_DOMAIN)) {
throw new PaymentRequiredException();
} else {
throw new UnauthorizedException();
}
} else if (nextTag.isStart("challenge")) {
final String challenge = tagReader.readElement(nextTag).getContent();
final Element response = new Element("response");
@ -1548,6 +1559,10 @@ public class XmppConnection implements Runnable {
}
private class PaymentRequiredException extends IOException {
}
public enum Identity {
FACEBOOK,
SLACK,

View file

@ -685,4 +685,5 @@
<string name="databaseimport_started">Backup will be imported, this may take awhile.</string>
<string name="pref_export_plain_text_logs_summary">Enable an export of chat logs as human readable text files</string>
<string name="pref_export_plain_text_logs">Export human readable chat logs</string>
<string name="payment_required">Payment required</string>
</resources>