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

chore(add-exceptions-when-mls-handling-fails) #WPB-12152 #18

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
target/
data/
libs/
mls/
.classpath
.project
.settings
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.wire</groupId>
<artifactId>helium</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>

<name>Helium</name>
<description>User mode for Wire Bots</description>
Expand Down Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>com.wire</groupId>
<artifactId>xenon</artifactId>
<version>1.7.0</version>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
Expand Down
129 changes: 62 additions & 67 deletions src/main/java/com/wire/helium/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ public boolean isMlsEnabled() {
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.get();

if (isErrorResponse(featureConfigsResponse.getStatus())) {
String msgError = featureConfigsResponse.readEntity(String.class);
Logger.error("isMlsEnabled - Public Keys error: %s, status: %d", msgError, featureConfigsResponse.getStatus());
if (isErrorResponse(mlsPublicKeysResponse.getStatus())) {
String msgError = mlsPublicKeysResponse.readEntity(String.class);
Logger.error("isMlsEnabled - Public Keys error: %s, status: %d", msgError, mlsPublicKeysResponse.getStatus());
return false;
}

Expand Down Expand Up @@ -684,27 +684,27 @@ public boolean isMlsEnabled() {
*
* @param clientId clientId to upload the public keys
* @param clientUpdate the public keys
* @throws RuntimeException if the request fails
*/
@Override
public void uploadClientPublicKey(String clientId, ClientUpdate clientUpdate) {
try {
Response response = clientsPath
.path(clientId)
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.put(Entity.json(clientUpdate));

if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error(
"uploadClientPublicKey error: %s, clientId: %s, status: %d",
msgError, clientId, response.getStatus()
);
} else if(isSuccessResponse(response.getStatus())) {
Logger.info("uploadClientPublicKey success for clientId: %s", clientId);
}
} catch (Exception e) {
Logger.error("uploadClientPublicKey error: %s", e.getMessage());
public void uploadClientPublicKey(String clientId, ClientUpdate clientUpdate) throws RuntimeException {
Response response = clientsPath
.path(clientId)
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.put(Entity.json(clientUpdate));

if (isErrorResponse(response.getStatus())) {
String errorResponse = response.readEntity(String.class);
String errorMessage = String.format(
"uploadClientPublicKey error: %s, clientId: %s, status: %d",
errorResponse, clientId, response.getStatus()
);

Logger.error(errorMessage);
throw new RuntimeException(errorResponse);
} else if(isSuccessResponse(response.getStatus())) {
Logger.info("uploadClientPublicKey success for clientId: %s", clientId);
}
}

Expand All @@ -719,29 +719,29 @@ public void uploadClientPublicKey(String clientId, ClientUpdate clientUpdate) {
*
* @param clientId clientId to upload the package keys
* @param keyPackageUpdate list of package keys
* @throws RuntimeException if the request fails
*/
@Override
public void uploadClientKeyPackages(String clientId, KeyPackageUpdate keyPackageUpdate) {
try {
Response response = mlsPath
.path("key-packages")
.path("self")
.path(clientId)
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.post(Entity.json(keyPackageUpdate));

if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error(
"getConversationGroupInfo error: %s, clientId: %s, status: %d",
msgError, clientId, response.getStatus()
);
} else if(isSuccessResponse(response.getStatus())) {
Logger.info("uploadClientKeyPackages success for clientId: %s", clientId);
}
} catch (Exception e) {
Logger.error("uploadClientKeyPackages, clientId: %s, error: %s", clientId, e.getMessage());
public void uploadClientKeyPackages(String clientId, KeyPackageUpdate keyPackageUpdate) throws RuntimeException {
Response response = mlsPath
.path("key-packages")
.path("self")
.path(clientId)
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.post(Entity.json(keyPackageUpdate));

if (isErrorResponse(response.getStatus())) {
String errorResponse = response.readEntity(String.class);
String errorMessage = String.format(
"getConversationGroupInfo error: %s, clientId: %s, status: %d",
errorResponse, clientId, response.getStatus()
);

Logger.error(errorMessage);
throw new RuntimeException(errorResponse);
} else if(isSuccessResponse(response.getStatus())) {
Logger.info("uploadClientKeyPackages success for clientId: %s", clientId);
}
}

Expand All @@ -760,38 +760,33 @@ public byte[] getConversationGroupInfo(QualifiedId conversationId) throws Runtim
return response.readEntity(byte[].class);
}

String errorResponse = response.readEntity(String.class);
if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error("getConversationGroupInfo error: %s, status: %d", msgError, response.getStatus());
Logger.error("getConversationGroupInfo error: %s, status: %d", errorResponse, response.getStatus());
}

throw new RuntimeException(
"getConversationGroupInfo failed",
new HttpException(response.readEntity(String.class), response.getStatus())
);
throw new RuntimeException(errorResponse);
}

@Override
public void commitMlsBundle(byte[] commitBundle) {
try {
Response response = mlsPath
.path("commit-bundles")
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.post(Entity.entity(commitBundle, "message/mls"));

if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error("commitMlsBundle error: %s, status: %d", msgError, response.getStatus());
}
Response response = mlsPath
.path("commit-bundles")
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.post(Entity.entity(commitBundle, "message/mls"));

if (isSuccessResponse(response.getStatus())) {
Logger.info("commitMlsBundle success.");
}
if (isSuccessResponse(response.getStatus())) {
Logger.info("commitMlsBundle success.");
return;
}

} catch (Exception e) {
Logger.error("commitMlsBundle error: %s", e.getMessage());
String errorResponse = response.readEntity(String.class);
if (isErrorResponse(response.getStatus())) {
Logger.error("commitMlsBundle error: %s, status: %d", errorResponse, response.getStatus());
}

throw new RuntimeException(errorResponse);
}

/**
Expand Down Expand Up @@ -825,12 +820,12 @@ public List<Conversation> getUserConversations() {
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.post(Entity.entity(pagingConfig, MediaType.APPLICATION_JSON));

if (listIdsResponse.getStatus() >= 400) {
if (isErrorResponse(listIdsResponse.getStatus())) {
String msgError = listIdsResponse.readEntity(String.class);
Logger.error("getUserConversations - List Ids error: %s, status: %d", msgError, listIdsResponse.getStatus());
}

if (listIdsResponse.getStatus() == 200) {
if (isSuccessResponse(listIdsResponse.getStatus())) {
ConversationListIdsResponse conversationListIds = listIdsResponse.readEntity(ConversationListIdsResponse.class);
hasMorePages = conversationListIds.hasMore;
pagingConfig.setPagingState(conversationListIds.pagingState);
Expand Down
Loading