Skip to content

Commit ecad437

Browse files
✨ add webhook error response (#345)
1 parent 1d1b906 commit ecad437

4 files changed

Lines changed: 92 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
391391

392392
<!-- Code dependencies -->
393-
<com.fasterxml.jackson.version>2.21.4</com.fasterxml.jackson.version>
393+
<com.fasterxml.jackson.version>2.21.5</com.fasterxml.jackson.version>
394394
<com.squareup.okhttp3.version>4.12.0</com.squareup.okhttp3.version>
395395
<info.picocli.version>4.7.7</info.picocli.version>
396396
<org.apache.commons.math3.version>3.6.1</org.apache.commons.math3.version>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.mindee.v2.parsing.inference;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6+
import com.mindee.v1.parsing.common.LocalDateTimeDeserializer;
7+
import com.mindee.v2.parsing.CommonResponse;
8+
import com.mindee.v2.parsing.error.ErrorResponse;
9+
import java.time.LocalDateTime;
10+
import lombok.Data;
11+
import lombok.EqualsAndHashCode;
12+
13+
/**
14+
* Represents an asynchronous polling response.
15+
*/
16+
@Data
17+
@EqualsAndHashCode(callSuper = true)
18+
@JsonIgnoreProperties(ignoreUnknown = true)
19+
public class FailedInferenceResponse extends CommonResponse {
20+
/**
21+
* UUID of the failed inference.
22+
*/
23+
@JsonProperty("inference_id")
24+
String inferenceId;
25+
26+
/**
27+
* UUID of the model used.
28+
*/
29+
@JsonProperty("model_id")
30+
String modelId;
31+
32+
/**
33+
* Name of the input file.
34+
*/
35+
@JsonProperty("file_name")
36+
String fileName;
37+
38+
/**
39+
* Alias sent for the file, if any
40+
*/
41+
@JsonProperty("file_alias")
42+
String fileAlias;
43+
44+
/**
45+
* Problem details for the failure, if available.
46+
*/
47+
@JsonProperty("error")
48+
ErrorResponse error;
49+
50+
/**
51+
* Date and time when the inference was started.
52+
*/
53+
@JsonProperty("created_at")
54+
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
55+
LocalDateTime createdAt;
56+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.mindee.v2.parsing;
2+
3+
import static com.mindee.TestingUtilities.getV2ResourcePath;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
8+
import com.mindee.v2.parsing.inference.FailedInferenceResponse;
9+
import java.io.IOException;
10+
import java.time.LocalDateTime;
11+
import org.junit.jupiter.api.DisplayName;
12+
import org.junit.jupiter.api.Test;
13+
14+
@DisplayName("MindeeV2 - Failed Inference Tests")
15+
public class FailedInferenceResponseTest {
16+
@Test
17+
@DisplayName("properties must be valid")
18+
void whenFailed_mustLoad() throws IOException {
19+
var localResponse = new LocalResponse(
20+
getV2ResourcePath("errors/webhook_error_500_failed.json")
21+
);
22+
var response = localResponse.deserializeResponse(FailedInferenceResponse.class);
23+
assertNotNull(response);
24+
assertEquals("12345678-1234-1234-1234-123456789ABC", response.getInferenceId());
25+
assertEquals("default_sample.jpg", response.getFileName());
26+
assertEquals("dummy-alias.jpg", response.getFileAlias());
27+
assertEquals("dummy-alias.jpg", response.getFileAlias());
28+
assertInstanceOf(LocalDateTime.class, response.getCreatedAt());
29+
assertNotNull(response.getError());
30+
assertNotNull(response.getError());
31+
assertEquals(500, response.getError().getStatus());
32+
assertEquals("500-012", response.getError().getCode());
33+
}
34+
}

src/test/resources

0 commit comments

Comments
 (0)