UNPKG

@handy-common-utils/misc-utils

Version:
48 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.couldBeNetworkingTimeoutError = couldBeNetworkingTimeoutError; exports.couldBeTemporaryNetworkingError = couldBeTemporaryNetworkingError; exports.couldBeServerError = couldBeServerError; function getErrorDetails(err) { var _a, _b, _c, _d, _e; const msg = (_b = (_a = err === null || err === void 0 ? void 0 : err.errorMessage) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : String(err); const statusCode = String((_e = (_d = (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : err === null || err === void 0 ? void 0 : err.statusCode) !== null && _e !== void 0 ? _e : err === null || err === void 0 ? void 0 : err.status); return { message: msg, statusCode }; } /** * Checks if the error could be a networking timeout error. * @param err The error to check. * @returns True if the error is a networking timeout error, false otherwise. */ function couldBeNetworkingTimeoutError(err) { if (err == null) { return false; } const { message, statusCode } = getErrorDetails(err); return statusCode === '504' || message.includes('ETIMEDOUT'); } /** * Checks if the error could be a temporary networking error. * @param err The error to check. * @returns True if the error is a temporary networking error, false otherwise. */ function couldBeTemporaryNetworkingError(err) { if (err == null) { return false; } const { message, statusCode } = getErrorDetails(err); return statusCode === '504' || message.includes('ECONNREFUSED') || message.includes('ETIMEDOUT') || message.includes('EAI_AGAIN') || message.includes('socket hang up'); } /** * Checks if the error could be a server error. * @param err The error to check. * @returns True if the error is a server error, false otherwise. */ function couldBeServerError(err) { if (err == null) { return false; } const { message, statusCode } = getErrorDetails(err); return /5\d{2}/.test(statusCode) || message.includes('Internal Server Error'); } //# sourceMappingURL=errors.js.map