Skip to content

Commit 45c2d88

Browse files
Merge #757
757: Fixing empty TaskError response r=curquiza a=larskristianhaga # Pull Request Seems like the `TaskError` object is only returning empty Strings when trying to get the error details of a task. Seems to be a missmatch between the field naming, and number of fields based on the API response. Therefor it dosent understand what to map, and only gives empty strings back. ## Related issue None ## What does this PR do? - It moves the `TaskError` class to the `model` package, closer to the usage in `Task` class. - Since its peers`TaskDetails`, and `TaskStatus` are already here. - Updates the field in `TaskError` to match the API naming, and number of fields. - Updates the Exception integration test to use the correct naming and import. - Adds Integration tests to check that `TaskError` fields is not blank or null. ## PR checklist Please check if your PR fulfills the following requirements: - [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [X] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: larskristianhaga <[email protected]>
2 parents d591794 + 725a05f commit 45c2d88

File tree

5 files changed

+64
-20
lines changed

5 files changed

+64
-20
lines changed

src/main/java/com/meilisearch/sdk/TaskError.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/com/meilisearch/sdk/model/Task.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.meilisearch.sdk.model;
22

3-
import com.meilisearch.sdk.TaskError;
43
import java.util.Date;
54
import lombok.Getter;
65

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.meilisearch.sdk.model;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
/** The code, type‚ error and message of the task error */
7+
@Getter
8+
@Setter
9+
public class TaskError {
10+
11+
public TaskError() {}
12+
13+
protected String code = "";
14+
protected String type = "";
15+
protected String link = "";
16+
protected String message = "";
17+
}

src/test/java/com/meilisearch/integration/ExceptionsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import com.meilisearch.integration.classes.AbstractIT;
99
import com.meilisearch.sdk.Client;
1010
import com.meilisearch.sdk.Config;
11-
import com.meilisearch.sdk.TaskError;
1211
import com.meilisearch.sdk.exceptions.APIError;
1312
import com.meilisearch.sdk.exceptions.MeilisearchApiException;
1413
import com.meilisearch.sdk.exceptions.MeilisearchCommunicationException;
14+
import com.meilisearch.sdk.model.TaskError;
1515
import org.junit.jupiter.api.AfterAll;
1616
import org.junit.jupiter.api.BeforeEach;
1717
import org.junit.jupiter.api.Tag;
@@ -60,8 +60,8 @@ public void testErrorSerializeAndGetters() {
6060
@Test
6161
public void testTaskErrorGetters() {
6262
TaskError error = new TaskError();
63-
error.setTaskErrorCode("wrong field");
64-
assertThat(error.getTaskErrorCode(), is(equalTo("wrong field")));
63+
error.setCode("wrong field");
64+
assertThat(error.getCode(), is(equalTo("wrong field")));
6565
}
6666

6767
/** Test MeilisearchApiException is thrown on Meilisearch bad request */

src/test/java/com/meilisearch/integration/TasksTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.meilisearch.integration;
22

33
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.blankOrNullString;
45
import static org.hamcrest.Matchers.equalTo;
56
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
67
import static org.hamcrest.Matchers.instanceOf;
78
import static org.hamcrest.Matchers.is;
9+
import static org.hamcrest.Matchers.not;
810
import static org.hamcrest.Matchers.notNullValue;
911
import static org.hamcrest.Matchers.nullValue;
1012
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -88,6 +90,48 @@ public void testClientGetTasksLimit() throws Exception {
8890
assertThat(result.getResults().length, is(notNullValue()));
8991
}
9092

93+
/** Test Get Task Error Values */
94+
@Test
95+
public void testClientGetTaskErrorValues() throws Exception {
96+
String indexUid = "CheckTaskErrorValues";
97+
Index index = client.index(indexUid);
98+
99+
// Deleting all documents from an index that does not exist results in a task error.
100+
TaskInfo taskInfo = index.deleteAllDocuments();
101+
index.waitForTask(taskInfo.getTaskUid());
102+
103+
Task task = client.getTask(taskInfo.getTaskUid());
104+
105+
assertThat(task.getError(), is(notNullValue()));
106+
assertThat(task.getError().getCode(), not(blankOrNullString()));
107+
assertThat(task.getError().getType(), not(blankOrNullString()));
108+
assertThat(task.getError().getLink(), not(blankOrNullString()));
109+
assertThat(task.getError().getMessage(), not(blankOrNullString()));
110+
}
111+
112+
/** Test Get Task Error Values When Adding Documents */
113+
@Test
114+
public void testClientGetTaskErrorWhenAddingDocuments() throws Exception {
115+
String indexUid = "CheckTaskErrorWhenAddingDocuments";
116+
Index index = client.index(indexUid);
117+
118+
TaskInfo taskInfo = client.createIndex(indexUid);
119+
client.waitForTask(taskInfo.getTaskUid());
120+
121+
String json = "{\"identifyer\": 1, \"name\": \"Donald Duck\"}";
122+
// Adding a document with a wrong identifier results in a task error.
123+
TaskInfo taskInfoAddDocuments = index.addDocuments(json, "identifier");
124+
client.waitForTask(taskInfoAddDocuments.getTaskUid());
125+
126+
Task task = client.getTask(taskInfoAddDocuments.getTaskUid());
127+
128+
assertThat(task.getError(), is(notNullValue()));
129+
assertThat(task.getError().getCode(), not(blankOrNullString()));
130+
assertThat(task.getError().getType(), not(blankOrNullString()));
131+
assertThat(task.getError().getLink(), not(blankOrNullString()));
132+
assertThat(task.getError().getMessage(), not(blankOrNullString()));
133+
}
134+
91135
/** Test Get Tasks with limit and from */
92136
@Test
93137
public void testClientGetTasksLimitAndFrom() throws Exception {

0 commit comments

Comments
 (0)