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

[ecovacs] Fix expired token handling for XML-over-MQTT models #17333

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -24,28 +24,35 @@ public class AbstractPortalIotCommandResponse {
@SerializedName("errno")
private final int errorCode;
@SerializedName("error")
private final String errorMessage;
private final Object errorObject; // might be a string or a JSON object

// unused field: 'id' (string)

public AbstractPortalIotCommandResponse(String result, int errorCode, String errorMessage) {
public AbstractPortalIotCommandResponse(String result, int errorCode, Object errorObject) {
this.result = result;
this.errorCode = errorCode;
this.errorMessage = errorMessage;
this.errorObject = errorObject;
}

public boolean wasSuccessful() {
return "ok".equals(result);
}

public boolean failedDueToAuthProblem() {
return "fail".equals(result) && errorMessage != null && errorMessage.toLowerCase().contains("auth error");
if (!"fail".equals(result)) {
return false;
}
if (errorCode == 3) {
// Error 3 is 'OAuth error'
return true;
}
String errorMessage = errorObject != null ? errorObject.toString().toLowerCase() : null;
return errorMessage != null && (errorMessage.contains("auth error") || errorMessage.contains("token error"));
Comment on lines +47 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
String errorMessage = errorObject != null ? errorObject.toString().toLowerCase() : null;
return errorMessage != null && (errorMessage.contains("auth error") || errorMessage.contains("token error"));
String errorMessage = errorObject != null ? errorObject.toString().toLowerCase() : "";
return errorMessage.contains("auth error") || errorMessage.contains("token error");

}

public String getErrorMessage() {
if (wasSuccessful()) {
return null;
}
String errorMessage = errorObject != null ? errorObject.toString() : null;
return "result=" + result + ", errno=" + errorCode + ", error=" + errorMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class PortalIotCommandJsonResponse extends AbstractPortalIotCommandRespon
@SerializedName("resp")
public final JsonElement response;

public PortalIotCommandJsonResponse(String result, JsonElement response, int errorCode, String errorMessage) {
super(result, errorCode, errorMessage);
public PortalIotCommandJsonResponse(String result, JsonElement response, int errorCode, Object errorObject) {
super(result, errorCode, errorObject);
this.response = response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class PortalIotCommandXmlResponse extends AbstractPortalIotCommandRespons
@SerializedName("resp")
private final String responseXml;

public PortalIotCommandXmlResponse(String result, String responseXml, int errorCode, String errorMessage) {
super(result, errorCode, errorMessage);
public PortalIotCommandXmlResponse(String result, String responseXml, int errorCode, Object errorObject) {
super(result, errorCode, errorObject);
this.responseXml = responseXml;
}

Expand Down