From 1a6b07fe7a1c63b0dd12a7095781ebc9db9a1612 Mon Sep 17 00:00:00 2001 From: Krishan Patel Date: Thu, 10 Jul 2025 10:36:37 +0100 Subject: [PATCH] . --- CHANGELOG.md | 1 + src/model/kibaException.ts | 6 +++++- src/requester/requester.ts | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c56675..473b5c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [MINOR] Use module-rolldown from build-js to build with rolldown - [MAJOR] Converted package into an es-module - [MINOR] Added `additionalHeaders` to `ServiceClient`.`makeRequest` +- [MINOR] Added `exceptionType` and `fields` to `KibaException` ### Changed diff --git a/src/model/kibaException.ts b/src/model/kibaException.ts index a8cf1e8..ed9a52f 100644 --- a/src/model/kibaException.ts +++ b/src/model/kibaException.ts @@ -1,10 +1,14 @@ export class KibaException extends Error { public statusCode: number; + public exceptionType: string; + public fields: Record; - public constructor(message: string, statusCode?: number) { + public constructor(message: string, statusCode?: number, exceptionType?: string, fields?: Record) { super(message); this.name = this.constructor.name; this.statusCode = statusCode || 500; + this.exceptionType = exceptionType || 'KibaException'; + this.fields = fields || {}; } } diff --git a/src/requester/requester.ts b/src/requester/requester.ts index 5cacbf9..8474f31 100644 --- a/src/requester/requester.ts +++ b/src/requester/requester.ts @@ -92,9 +92,11 @@ export class Requester { // no-op } if (errorContent && 'message' in errorContent) { - throw new KibaException(errorContent.message, response.status); + const fields = errorContent.fields || {}; + const exceptionType = errorContent.exceptionType || undefined; + throw new KibaException(errorContent.message, response.status, exceptionType, fields); } - throw new KibaException(response.content, response.status); + throw new KibaException(response.content, response.status, undefined, {}); } return response; };