Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/errors/mindeeError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorDetails, ErrorResponse } from "../parsing/v2";
import { ErrorDetails, ErrorResponse, ErrorItem } from "../parsing/v2";

/**
* Main Mindee Error custom class.
Expand Down Expand Up @@ -47,13 +47,15 @@ export class MindeeHttpErrorV2 extends MindeeError implements ErrorDetails {
public detail: string;
public title: string;
public code: string;
public errors: ErrorItem[];

constructor(error: ErrorResponse) {
super(`HTTP ${error.status} :: ${error.title} - ${error.detail}`);
super(`HTTP ${error.status} - ${error.title} :: ${error.code} - ${error.detail}`);
this.status = error.status;
this.detail = error.detail;
this.title = error.title;
this.code = error.code;
this.errors = error.errors;
this.name = "MindeeHttpErrorV2";
}
}
9 changes: 5 additions & 4 deletions src/parsing/v2/errorResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface ErrorDetails {
* A machine-readable code specific to the occurrence of the problem.
*/
code: string;
/**
* A machine-readable code specific to the occurrence of the problem.
*/
errors: ErrorItem[];
}

/**
Expand All @@ -28,10 +32,7 @@ export class ErrorResponse implements ErrorDetails {
detail: string;
title: string;
code: string;
/**
* A machine-readable code specific to the occurrence of the problem.
*/
public errors: ErrorItem[];
errors: ErrorItem[];

/**
* @param serverResponse JSON response from the server.
Expand Down
2 changes: 1 addition & 1 deletion tests/data
2 changes: 2 additions & 0 deletions tests/v2/clientV2.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
expect(errObj.code.startsWith("422-")).to.be.true;
expect(errObj.title).to.be.a("string");
expect(errObj.detail).to.be.a("string");
expect(errObj.errors).to.be.instanceOf(Array);
}
}).timeout(60000);

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

Expand Down
11 changes: 10 additions & 1 deletion tests/v2/parsing/inference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,23 @@ describe("MindeeV2 - Inference Response", async () => {
});

describe("RAG Metadata", async () => {
it("RAG metadata should be exposed", async () => {
it("RAG metadata when matched", async () => {
const response = await loadV2Inference(
path.join(inferencePath, "rag_matched.json")
);
const rag = response.inference.result.rag;
expect(rag).to.be.instanceOf(RagMetadata);
expect(rag?.retrievedDocumentId).to.eq("12345abc-1234-1234-1234-123456789abc");
});

it("RAG metadata when not matched", async () => {
const response = await loadV2Inference(
path.join(inferencePath, "rag_not_matched.json")
);
const rag = response.inference.result.rag;
expect(rag).to.be.instanceOf(RagMetadata);
expect(rag?.retrievedDocumentId).to.be.undefined;
});
});

describe("RST Display", async () => {
Expand Down