From b5d3859b22c44552d2c0165383fd5b1be2844a91 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 16 Aug 2016 10:39:59 +0200 Subject: add payment required error --- .../java/eu/siacs/conversations/entities/Account.java | 5 ++++- .../eu/siacs/conversations/xmpp/XmppConnection.java | 17 ++++++++++++++++- src/main/res/values/strings.xml | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 7085c7ba..b77d85c4 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -111,7 +111,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; @@ -169,6 +170,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; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 89ffa05d..6e36a546 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -384,6 +384,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) { @@ -505,7 +507,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"); @@ -1535,6 +1546,10 @@ public class XmppConnection implements Runnable { } + private class PaymentRequiredException extends IOException { + + } + public enum Identity { FACEBOOK, SLACK, diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 96d7d3cc..71b641db 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -674,4 +674,5 @@ Tablet Web browser Console + Payment required -- cgit v1.2.3