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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/model/kibaException.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

export class KibaException extends Error {
public statusCode: number;
public exceptionType: string;
public fields: Record<string, string>;

public constructor(message: string, statusCode?: number) {
public constructor(message: string, statusCode?: number, exceptionType?: string, fields?: Record<string, string>) {
super(message);
this.name = this.constructor.name;
this.statusCode = statusCode || 500;
this.exceptionType = exceptionType || 'KibaException';
this.fields = fields || {};
}
}
6 changes: 4 additions & 2 deletions src/requester/requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading