diff --git a/constructorio-client/src/main/java/io/constructor/client/models/Task.java b/constructorio-client/src/main/java/io/constructor/client/models/Task.java index dd27092c..c5d18c1c 100644 --- a/constructorio-client/src/main/java/io/constructor/client/models/Task.java +++ b/constructorio-client/src/main/java/io/constructor/client/models/Task.java @@ -32,6 +32,9 @@ public class Task { @SerializedName("result") private Object result; + @SerializedName("error") + private TaskError error; + /** * @return the id */ @@ -95,6 +98,13 @@ public Object getResult() { return result; } + /** + * @return the error + */ + public TaskError getError() { + return error; + } + public void setId(int id) { this.id = id; } @@ -130,4 +140,8 @@ public void setProtocol(String protocol) { public void setResult(Object result) { this.result = result; } + + public void setError(TaskError error) { + this.error = error; + } } diff --git a/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java b/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java new file mode 100644 index 00000000..a9884e17 --- /dev/null +++ b/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java @@ -0,0 +1,21 @@ +package io.constructor.client.models; + +import com.google.gson.annotations.SerializedName; + +/** Constructor.io Task Error... uses Gson/Reflection to load data in */ +public class TaskError { + + @SerializedName("message") + private String message; + + /** + * @return the error message + */ + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java index c1b30830..2f85b733 100644 --- a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java +++ b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java @@ -30,6 +30,20 @@ public void createTaskResponseWithQueuedTaskShouldReturnAResult() throws Excepti assertNull(response.getResult()); } + @Test + public void createTaskResponseWithErrorTaskShouldReturnAResult() throws Exception { + String string = Utils.getTestResource("response.task.error.json"); + Task response = ConstructorIO.createTaskResponse(string); + + assertEquals("id exists", 100721281, response.getId()); + assertEquals("status exists", "FAILED", response.getStatus()); + assertEquals( + "Error message exists", + "IngestionError: The items file you have uploaded is empty. Please fix it and try" + + " again.", + response.getError().getMessage()); + } + @Test public void createTaskResponseWithDoneTaskShouldReturnAResult() throws Exception { String string = Utils.getTestResource("response.task.done.json"); diff --git a/constructorio-client/src/test/resources/response.task.error.json b/constructorio-client/src/test/resources/response.task.error.json new file mode 100644 index 00000000..7114d3ea --- /dev/null +++ b/constructorio-client/src/test/resources/response.task.error.json @@ -0,0 +1,14 @@ +{ + "id": 100721281, + "status": "FAILED", + "submission_time": "2024-08-21T18:11:49", + "last_update": "2024-08-21T18:11:53", + "start_time": "2024-08-21T18:11:51", + "type": "ingestion", + "error": { + "message": "IngestionError: The items file you have uploaded is empty. Please fix it and try again." + }, + "filename": "filename", + "protocol": "http", + "ingestion_type": "patchdelta" +} \ No newline at end of file