From 827b2e6e46730035a7b1c0ce52bef2c34ed308e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Tue, 28 Oct 2025 11:23:17 +0100 Subject: [PATCH] :loud_sound: add error code to v2 exceptions --- src/errors/mindeeError.ts | 6 ++++-- src/parsing/v2/errorResponse.ts | 9 +++++---- tests/data | 2 +- tests/v2/clientV2.integration.ts | 2 ++ tests/v2/parsing/inference.spec.ts | 11 ++++++++++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/errors/mindeeError.ts b/src/errors/mindeeError.ts index b70e4385..53c90ff6 100644 --- a/src/errors/mindeeError.ts +++ b/src/errors/mindeeError.ts @@ -1,4 +1,4 @@ -import { ErrorDetails, ErrorResponse } from "../parsing/v2"; +import { ErrorDetails, ErrorResponse, ErrorItem } from "../parsing/v2"; /** * Main Mindee Error custom class. @@ -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"; } } diff --git a/src/parsing/v2/errorResponse.ts b/src/parsing/v2/errorResponse.ts index 38ca3346..bd5976e9 100644 --- a/src/parsing/v2/errorResponse.ts +++ b/src/parsing/v2/errorResponse.ts @@ -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[]; } /** @@ -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. diff --git a/tests/data b/tests/data index f2e8bad3..7d843db0 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit f2e8bad343c51747a18949b46d5be105ff068232 +Subproject commit 7d843db01df952740d0f2d39f62fc3efb86f92bb diff --git a/tests/v2/clientV2.integration.ts b/tests/v2/clientV2.integration.ts index 9e618b4f..0611fbb8 100644 --- a/tests/v2/clientV2.integration.ts +++ b/tests/v2/clientV2.integration.ts @@ -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); @@ -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); diff --git a/tests/v2/parsing/inference.spec.ts b/tests/v2/parsing/inference.spec.ts index 9c60e33c..080610cf 100644 --- a/tests/v2/parsing/inference.spec.ts +++ b/tests/v2/parsing/inference.spec.ts @@ -280,7 +280,7 @@ 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") ); @@ -288,6 +288,15 @@ describe("MindeeV2 - Inference Response", async () => { 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 () => {