Files
onspring-api-sdk-javascript/src/models/ApiResponse.ts
T

39 lines
1.1 KiB
TypeScript
Raw Normal View History

/**
* @class ApiResponse - A generic response object for API requests.
*/
export class ApiResponse<T> {
/**
* @property {number} statusCode - The status code of the response.
*/
readonly statusCode: number;
/**
* @property {boolean} isSuccessful - True if the status code is less than 400; otherwise, false.
*/
readonly isSuccessful: boolean;
/**
* @property {string} message - The message of the response.
*/
readonly message: string;
/**
* @property {T} data - The data of the response.
*/
readonly data: T;
/**
* @constructor - Creates a new instance of the ApiResponse class.
* @param {number} statusCode - The status code of the response.
* @param {string} message - The message of the response.
* @param {T} data - The data of the response.
* @returns {ApiResponse<T>} - A new instance of the ApiResponse class.
*/
constructor(statusCode: number, message: string, data: T) {
this.statusCode = statusCode;
this.isSuccessful = statusCode < 400;
this.message = message;
this.data = data;
}
}