Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xmlrpc login errors. #2280

Merged
merged 6 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.android.volley.toolbox.HttpHeaderParser;

import org.wordpress.android.fluxc.FluxCError;
import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest;
import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType;
import org.wordpress.android.fluxc.store.AccountStore.AuthenticateErrorPayload;
import org.wordpress.android.fluxc.utils.ErrorUtils.OnUnexpectedError;
import org.wordpress.android.util.AppLog;
Expand All @@ -28,6 +30,9 @@

import javax.net.ssl.SSLHandshakeException;

import static org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType.METHOD_NOT_ALLOWED;
import static org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType.NOT_SET;

public abstract class BaseRequest<T> extends Request<T> {
public static final int DEFAULT_REQUEST_TIMEOUT = 30000;
public static final int UPLOAD_REQUEST_READ_TIMEOUT = 60000;
Expand Down Expand Up @@ -62,6 +67,7 @@ public static class BaseNetworkError implements FluxCError {
public GenericErrorType type;
public String message;
public VolleyError volleyError;
public XmlRpcErrorType xmlRpcErrorType = NOT_SET;

public BaseNetworkError(@NonNull BaseNetworkError error) {
this.message = error.message;
Expand All @@ -80,14 +86,32 @@ public BaseNetworkError(@NonNull GenericErrorType error, @NonNull VolleyError vo
this.type = error;
this.volleyError = volleyError;
}
public BaseNetworkError(@NonNull GenericErrorType error,
@NonNull VolleyError volleyError,
@NonNull XmlRpcErrorType xmlRpcErrorType) {
this.message = "";
this.type = error;
this.volleyError = volleyError;
this.xmlRpcErrorType = xmlRpcErrorType;
}
public BaseNetworkError(@NonNull VolleyError volleyError) {
this.type = GenericErrorType.UNKNOWN;
this.message = "";
this.volleyError = volleyError;
}
public BaseNetworkError(@NonNull VolleyError volleyError, @NonNull XmlRpcErrorType xmlRpcErrorType) {
this.type = GenericErrorType.UNKNOWN;
this.message = "";
this.volleyError = volleyError;
this.xmlRpcErrorType = xmlRpcErrorType;
}
public BaseNetworkError(@NonNull GenericErrorType error) {
this.type = error;
}
public BaseNetworkError(@NonNull GenericErrorType error, @NonNull XmlRpcErrorType xmlRpcErrorType) {
this.type = error;
this.xmlRpcErrorType = xmlRpcErrorType;
}
public boolean isGeneric() {
return type != null;
}
Expand Down Expand Up @@ -309,6 +333,10 @@ private BaseNetworkError getBaseNetworkError(VolleyError volleyError) {
switch (volleyError.networkResponse.statusCode) {
case 404:
return new BaseNetworkError(GenericErrorType.NOT_FOUND, volleyError.getMessage(), volleyError);
case 405:
return this instanceof XMLRPCRequest
? new BaseNetworkError(volleyError, METHOD_NOT_ALLOWED)
: new BaseNetworkError(volleyError);
case 451:
return new BaseNetworkError(GenericErrorType.CENSORED, volleyError.getMessage(), volleyError);
case 500:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public class XMLRPCRequest extends BaseRequest<Object> {
private final Object[] mParams;
private final XmlSerializer mSerializer = Xml.newSerializer();

public enum XmlRpcErrorType {
NOT_SET,
METHOD_NOT_ALLOWED,
UNABLE_TO_READ_SITE,
AUTH_REQUIRED
}

public XMLRPCRequest(String url, XMLRPC method, List<Object> params, Listener<? super Object[]> listener,
BaseErrorListener errorListener) {
super(Method.POST, url, errorListener);
Expand Down Expand Up @@ -119,6 +126,7 @@ public BaseNetworkError deliverBaseNetworkError(@NonNull BaseNetworkError error)
switch (error.type) {
case HTTP_AUTH_ERROR:
payload.error.type = AuthenticationErrorType.HTTP_AUTH_ERROR;
payload.error.xmlRpcErrorType = XmlRpcErrorType.AUTH_REQUIRED;
break;
case INVALID_SSL_CERTIFICATE:
payload.error.type = AuthenticationErrorType.INVALID_SSL_CERTIFICATE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.wordpress.android.fluxc.generated.endpoint.XMLRPC
import org.wordpress.android.fluxc.network.BaseRequest
import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError
import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType.INVALID_RESPONSE
import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType
import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequestBuilder.Response.Error
import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequestBuilder.Response.Success
import javax.inject.Inject
Expand Down Expand Up @@ -37,7 +38,7 @@ class XMLRPCRequestBuilder
try {
clazz.cast(obj)?.let { listener(it) }
} catch (e: ClassCastException) {
errorListener.invoke(BaseNetworkError(INVALID_RESPONSE))
errorListener.invoke(BaseNetworkError(INVALID_RESPONSE, XmlRpcErrorType.UNABLE_TO_READ_SITE))
}
}, errorListener)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.wordpress.android.fluxc.network.rest.wpcom.auth.Authenticator;
import org.wordpress.android.fluxc.network.rest.wpcom.auth.Authenticator.AuthEmailResponsePayload;
import org.wordpress.android.fluxc.network.rest.wpcom.auth.Authenticator.Token;
import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType;
import org.wordpress.android.fluxc.persistence.AccountSqlUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
Expand All @@ -49,6 +50,8 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import static org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType.NOT_SET;

/**
* In-memory based and persisted in SQLite.
*/
Expand All @@ -74,6 +77,10 @@ public AuthenticateErrorPayload(@NonNull AuthenticationError error) {
public AuthenticateErrorPayload(@NonNull AuthenticationErrorType errorType) {
this.error = new AuthenticationError(errorType, "");
}
public AuthenticateErrorPayload(@NonNull AuthenticationErrorType errorType,
@NonNull XmlRpcErrorType xmlRpcErrorType) {
this.error = new AuthenticationError(errorType, "", xmlRpcErrorType);
}
}

public static class AuthEmailPayload extends Payload<BaseNetworkError> {
Expand Down Expand Up @@ -446,10 +453,19 @@ public OnAuthEmailSent(boolean isSignup) {
public static class AuthenticationError implements OnChangedError {
public AuthenticationErrorType type;
public String message;
public XmlRpcErrorType xmlRpcErrorType = NOT_SET;

public AuthenticationError(AuthenticationErrorType type, @NonNull String message) {
this.type = type;
this.message = message;
}
public AuthenticationError(AuthenticationErrorType type,
@NonNull String message,
XmlRpcErrorType xmlRpcErrorType) {
this.type = type;
this.message = message;
this.xmlRpcErrorType = xmlRpcErrorType;
}
}

public static class OnSubscriptionsChanged extends OnChanged<SubscriptionsError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import org.wordpress.android.fluxc.store.SiteStore.DomainAvailabilityErrorType.I
import org.wordpress.android.fluxc.store.SiteStore.DomainSupportedStatesErrorType.INVALID_COUNTRY_CODE
import org.wordpress.android.fluxc.store.SiteStore.ExportSiteErrorType.GENERIC_ERROR
import org.wordpress.android.fluxc.store.SiteStore.PlansErrorType.NOT_AVAILABLE
import org.wordpress.android.fluxc.store.SiteStore.SelfHostedErrorType.NOT_SET
import org.wordpress.android.fluxc.store.SiteStore.SiteErrorType.DUPLICATE_SITE
import org.wordpress.android.fluxc.store.SiteStore.SiteErrorType.UNAUTHORIZED
import org.wordpress.android.fluxc.store.SiteStore.SiteErrorType.UNKNOWN_SITE
Expand Down Expand Up @@ -405,7 +406,8 @@ open class SiteStore

data class SiteError @JvmOverloads constructor(
@JvmField val type: SiteErrorType,
@JvmField val message: String? = null
@JvmField val message: String? = null,
@JvmField val selfHostedErrorType: SelfHostedErrorType = NOT_SET
) : OnChangedError

data class SiteEditorsError internal constructor(
Expand Down Expand Up @@ -810,6 +812,12 @@ open class SiteStore
GENERIC_ERROR
}

enum class SelfHostedErrorType {
NOT_SET,
XML_RPC_SERVICES_DISABLED,
UNABLE_TO_READ_SITE
}

enum class DeleteSiteErrorType {
INVALID_SITE, UNAUTHORIZED, // user don't have permission to delete
AUTHORIZATION_REQUIRED, // missing access token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.fluxc.utils;

import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError;
import org.wordpress.android.fluxc.store.SiteStore.SelfHostedErrorType;
import org.wordpress.android.fluxc.store.SiteStore.SiteError;
import org.wordpress.android.fluxc.store.SiteStore.SiteErrorType;

Expand All @@ -14,6 +15,23 @@ public static SiteError genericToSiteError(BaseNetworkError error) {
break;
}
}
return new SiteError(errorType, error.message);

SiteError siteError = new SiteError(errorType, error.message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very minor NP - maybe we can avoid a double initialization of siteError here? If it makes sense :)


switch (error.xmlRpcErrorType) {
case METHOD_NOT_ALLOWED:
siteError = new SiteError(errorType, error.message, SelfHostedErrorType.XML_RPC_SERVICES_DISABLED);
break;
case UNABLE_TO_READ_SITE:
siteError = new SiteError(errorType, error.message, SelfHostedErrorType.UNABLE_TO_READ_SITE);
break;
case AUTH_REQUIRED:
case NOT_SET:
default:
// Nothing to do
break;
}

return siteError;
}
}