Skip to content

Commit 4ac5fa0

Browse files
authored
🔊 add error code to v2 exceptions (#399)
1 parent 176c3d3 commit 4ac5fa0

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

src/errors/mindeeError.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ErrorDetails, ErrorResponse } from "../parsing/v2";
1+
import { ErrorDetails, ErrorResponse, ErrorItem } from "../parsing/v2";
22

33
/**
44
* Main Mindee Error custom class.
@@ -47,13 +47,15 @@ export class MindeeHttpErrorV2 extends MindeeError implements ErrorDetails {
4747
public detail: string;
4848
public title: string;
4949
public code: string;
50+
public errors: ErrorItem[];
5051

5152
constructor(error: ErrorResponse) {
52-
super(`HTTP ${error.status} :: ${error.title} - ${error.detail}`);
53+
super(`HTTP ${error.status} - ${error.title} :: ${error.code} - ${error.detail}`);
5354
this.status = error.status;
5455
this.detail = error.detail;
5556
this.title = error.title;
5657
this.code = error.code;
58+
this.errors = error.errors;
5759
this.name = "MindeeHttpErrorV2";
5860
}
5961
}

src/parsing/v2/errorResponse.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export interface ErrorDetails {
1818
* A machine-readable code specific to the occurrence of the problem.
1919
*/
2020
code: string;
21+
/**
22+
* A machine-readable code specific to the occurrence of the problem.
23+
*/
24+
errors: ErrorItem[];
2125
}
2226

2327
/**
@@ -28,10 +32,7 @@ export class ErrorResponse implements ErrorDetails {
2832
detail: string;
2933
title: string;
3034
code: string;
31-
/**
32-
* A machine-readable code specific to the occurrence of the problem.
33-
*/
34-
public errors: ErrorItem[];
35+
errors: ErrorItem[];
3536

3637
/**
3738
* @param serverResponse JSON response from the server.

tests/data

tests/v2/clientV2.integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
158158
expect(errObj.code.startsWith("422-")).to.be.true;
159159
expect(errObj.title).to.be.a("string");
160160
expect(errObj.detail).to.be.a("string");
161+
expect(errObj.errors).to.be.instanceOf(Array);
161162
}
162163
}).timeout(60000);
163164

@@ -172,6 +173,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
172173
expect(errObj.code.startsWith("422-")).to.be.true;
173174
expect(errObj.title).to.be.a("string");
174175
expect(errObj.detail).to.be.a("string");
176+
expect(errObj.errors).to.be.instanceOf(Array);
175177
}
176178
}).timeout(60000);
177179

tests/v2/parsing/inference.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,23 @@ describe("MindeeV2 - Inference Response", async () => {
280280
});
281281

282282
describe("RAG Metadata", async () => {
283-
it("RAG metadata should be exposed", async () => {
283+
it("RAG metadata when matched", async () => {
284284
const response = await loadV2Inference(
285285
path.join(inferencePath, "rag_matched.json")
286286
);
287287
const rag = response.inference.result.rag;
288288
expect(rag).to.be.instanceOf(RagMetadata);
289289
expect(rag?.retrievedDocumentId).to.eq("12345abc-1234-1234-1234-123456789abc");
290290
});
291+
292+
it("RAG metadata when not matched", async () => {
293+
const response = await loadV2Inference(
294+
path.join(inferencePath, "rag_not_matched.json")
295+
);
296+
const rag = response.inference.result.rag;
297+
expect(rag).to.be.instanceOf(RagMetadata);
298+
expect(rag?.retrievedDocumentId).to.be.undefined;
299+
});
291300
});
292301

293302
describe("RST Display", async () => {

0 commit comments

Comments
 (0)