File tree Expand file tree Collapse file tree 12 files changed +217
-42
lines changed Expand file tree Collapse file tree 12 files changed +217
-42
lines changed Original file line number Diff line number Diff line change 33import com .mindee .InferenceParameters ;
44import com .mindee .input .LocalInputSource ;
55import com .mindee .input .URLInputSource ;
6+ import com .mindee .parsing .v2 .ErrorResponse ;
67import com .mindee .parsing .v2 .InferenceResponse ;
78import com .mindee .parsing .v2 .JobResponse ;
89import java .io .IOException ;
@@ -44,4 +45,17 @@ public abstract JobResponse reqGetJob(
4445 * @param inferenceId ID of the inference to poll.
4546 */
4647 abstract public InferenceResponse reqGetInference (String inferenceId );
48+
49+ /**
50+ * Creates an "unknown error" response from an HTTP status code.
51+ */
52+ protected ErrorResponse makeUnknownError (int statusCode ) {
53+ return new ErrorResponse (
54+ "Unknown Error" ,
55+ "The server returned an Unknown error." ,
56+ statusCode ,
57+ statusCode + "-000" ,
58+ null
59+ );
60+ }
4761}
Original file line number Diff line number Diff line change @@ -236,7 +236,7 @@ private MindeeHttpExceptionV2 getHttpError(ClassicHttpResponse response) {
236236 ErrorResponse err = mapper .readValue (rawBody , ErrorResponse .class );
237237
238238 if (err .getDetail () == null ) {
239- err = new ErrorResponse ( "Unknown error" , response .getCode ());
239+ err = makeUnknownError ( response .getCode ());
240240 }
241241 return new MindeeHttpExceptionV2 (err .getStatus (), err .getDetail ());
242242
@@ -321,10 +321,10 @@ private <R extends CommonResponse> R deserializeOrThrow(
321321 try {
322322 err = mapper .readValue (body , ErrorResponse .class );
323323 if (err .getDetail () == null ) {
324- err = new ErrorResponse ( "Unknown error" , httpStatus );
324+ err = makeUnknownError ( httpStatus );
325325 }
326326 } catch (Exception ignored ) {
327- err = new ErrorResponse ( "Unknown error" , httpStatus );
327+ err = makeUnknownError ( httpStatus );
328328 }
329329 throw new MindeeHttpExceptionV2 (err .getStatus (), err .getDetail ());
330330 }
Original file line number Diff line number Diff line change 1+ package com .mindee .parsing .v2 ;
2+
3+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
4+ import com .fasterxml .jackson .annotation .JsonProperty ;
5+ import lombok .AllArgsConstructor ;
6+ import lombok .EqualsAndHashCode ;
7+ import lombok .Getter ;
8+ import lombok .NoArgsConstructor ;
9+
10+ /**
11+ * Error item model.
12+ */
13+ @ Getter
14+ @ EqualsAndHashCode
15+ @ JsonIgnoreProperties (ignoreUnknown = true )
16+ @ AllArgsConstructor
17+ @ NoArgsConstructor
18+ public final class ErrorItem {
19+ /**
20+ * A JSON Pointer to the location of the body property.
21+ */
22+ @ JsonProperty ("pointer" )
23+ private String pointer ;
24+
25+ /**
26+ * Explicit information on the issue.
27+ */
28+ @ JsonProperty ("detail" )
29+ private String detail ;
30+ }
Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
44import com .fasterxml .jackson .annotation .JsonProperty ;
5+ import java .util .List ;
56import lombok .AllArgsConstructor ;
67import lombok .EqualsAndHashCode ;
78import lombok .Getter ;
89import lombok .NoArgsConstructor ;
910
1011/**
11- * Error information from the API .
12+ * Error response detailing a problem. The format adheres to RFC 9457 .
1213 */
1314@ Getter
1415@ EqualsAndHashCode
1718@ NoArgsConstructor
1819public final class ErrorResponse {
1920 /**
20- * Detail relevant to the error.
21+ * A short, human-readable summary of the problem.
22+ */
23+ @ JsonProperty ("title" )
24+ private String title ;
25+
26+ /**
27+ * A human-readable explanation specific to the occurrence of the problem.
2128 */
2229 @ JsonProperty ("detail" )
2330 private String detail ;
2431
2532 /**
26- * HTTP error code.
33+ * The HTTP status code returned by the server .
2734 */
2835 @ JsonProperty ("status" )
2936 private int status ;
3037
38+ /**
39+ * A machine-readable code specific to the occurrence of the problem.
40+ */
41+ @ JsonProperty ("code" )
42+ private String code ;
43+
44+ /**
45+ * The HTTP status code returned by the server.
46+ */
47+ @ JsonProperty ("errors" )
48+ private List <ErrorItem > errors ;
49+
3150 /** For prettier display. */
3251 @ Override
3352 public String toString () {
34- return "HTTP Status: " + status + " - " + detail ;
53+ return "HTTP " + status + " - " + title + " :: " + code + " - " + detail ;
3554 }
3655}
Original file line number Diff line number Diff line change 2020public final class InferenceResult {
2121
2222 /**
23- * Model fields.
23+ * Extracted fields, the key corresponds to the field's name in the data schema .
2424 */
2525 @ JsonProperty ("fields" )
2626 private InferenceFields fields ;
2727
2828 /**
29- * Options .
29+ * Raw text extracted from all pages in the document .
3030 */
3131 @ JsonProperty ("raw_text" )
3232 private RawText rawText ;
3333
34+ /**
35+ * RAG metadata.
36+ */
37+ @ JsonProperty ("rag" )
38+ private RagMetadata rag ;
39+
3440 @ Override
3541 public String toString () {
3642 StringJoiner joiner = new StringJoiner ("\n " );
Original file line number Diff line number Diff line change 1+ package com .mindee .parsing .v2 ;
2+
3+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
4+ import com .fasterxml .jackson .annotation .JsonProperty ;
5+ import lombok .AllArgsConstructor ;
6+ import lombok .Getter ;
7+ import lombok .NoArgsConstructor ;
8+
9+ /**
10+ * RAG metadata.
11+ */
12+ @ Getter
13+ @ JsonIgnoreProperties (ignoreUnknown = true )
14+ @ AllArgsConstructor
15+ @ NoArgsConstructor
16+ public final class RagMetadata {
17+ /**
18+ * The UUID of the matched document used during the RAG operation.
19+ */
20+ @ JsonProperty ("retrieved_document_id" )
21+ private String retrievedDocumentId ;
22+ }
Original file line number Diff line number Diff line change 1616@ AllArgsConstructor
1717@ NoArgsConstructor
1818public class RawText {
19- /*
19+ /**
2020 * Page Number the text was found on.
2121 */
2222 @ JsonProperty ("pages" )
Original file line number Diff line number Diff line change 2020
2121@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
2222@ Tag ("integration" )
23- @ DisplayName ("MindeeClientV2 – integration tests (V2) " )
23+ @ DisplayName ("MindeeV2 – Integration Tests " )
2424class MindeeClientV2IT {
2525
2626 private MindeeClientV2 mindeeClient ;
Original file line number Diff line number Diff line change 1919import static org .mockito .ArgumentMatchers .*;
2020import static org .mockito .Mockito .*;
2121
22- @ DisplayName ("MindeeClientV2 – client / API interaction tests " )
22+ @ DisplayName ("MindeeV2 – Client and API Tests " )
2323class MindeeClientV2Test {
2424 /**
2525 * Creates a fully mocked MindeeClientV2.
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ public static Path getV1ResourcePath(String filePath) {
1818 return Paths .get ("src/test/resources/v1/" + filePath );
1919 }
2020
21+ public static Path getV2ResourcePath (String filePath ) {
22+ return Paths .get ("src/test/resources/v2/" + filePath );
23+ }
24+
2125 public static String getV1ResourcePathString (String filePath ) {
2226 return getV1ResourcePath (filePath ).toString ();
2327 }
You can’t perform that action at this time.
0 commit comments