aveazul
Version:
Bluebird drop-in replacement built on native Promise
43 lines • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperationalError = void 0;
exports.isOperationalError = isOperationalError;
exports.isProgrammerError = isProgrammerError;
/**
* OperationalError class for representing errors that are expected during normal operation
* Similar to Bluebird's OperationalError
*/
class OperationalError extends Error {
constructor(message) {
super(message);
this.name = "OperationalError";
this.isOperational = true;
// Capture stack trace
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
exports.OperationalError = OperationalError;
/**
* Check if an error is an operational error
* @param error - Error to check
* @returns True if the error is operational
*/
function isOperationalError(error) {
if (!error || typeof error !== "object")
return false;
return (error instanceof OperationalError ||
error.isOperational === true);
}
/**
* Check if an error is a programmer error (unexpected, likely a bug)
* @param error - Error to check
* @returns True if the error is a programmer error
*/
function isProgrammerError(error) {
if (!error || typeof error !== "object")
return false;
return !isOperationalError(error);
}
//# sourceMappingURL=operational-error.cjs.map