Skip to content

Commit

Permalink
api error interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Dec 8, 2024
1 parent b0e7c9b commit fa0edce
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/interfaces/api_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Interface representing the structure of an API error.
*/
export interface ApiError {
/**
* The error message.
*/
message: string;

/**
* The error code representing the type of API error.
*/
code: number;

/**
* Additional details about the error (optional).
*/
details?: any;
}
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { AuthData } from "./auth_data.js";
export { ApiError } from "./api_error.js";
export { AuthError } from "./auth_error.js";
export { Branch } from "./branch.js";
export { BulkResult } from "./bulk_result.js";
Expand Down
23 changes: 21 additions & 2 deletions src/models/api_error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
export class ApiError extends Error {
import type { ApiError as ApiErrorInterface } from "../interfaces/api_error.js";

/**
* Represents an API error with a specific code and optional details.
*/
export class ApiError extends Error implements ApiErrorInterface {
/**
* The error code representing the type of API error.
*/
code: number;

/**
* Additional details about the error (optional).
*/
details?: any;

constructor(message: string, code: number, details: any) {
/**
* Creates an instance of ApiError.
*
* @param {string} message - The error message.
* @param {number} code - The error code.
* @param {any} [details] - Additional details about the error.
*/
constructor(message: string, code: number, details?: any) {
super(message);
this.code = code;
this.details = details;
Expand Down

0 comments on commit fa0edce

Please sign in to comment.