api-stds
Version:
Standardized API response and error handling toolkit with async handler, requestId, logging, and configurable formats.
22 lines (21 loc) • 530 B
JavaScript
// APIError.ts
export class ApiError extends Error {
statusCode;
data;
success;
errors;
constructor(statusCode, message = "Something went wrong", errors = [], stack = "") {
super(message);
this.statusCode = statusCode;
this.data = null;
this.message = message;
this.success = false;
this.errors = errors;
if (stack) {
this.stack = stack;
}
else {
Error.captureStackTrace(this, this.constructor);
}
}
}