UNPKG

steadybit

Version:

Command-line interface to interact with the Steadybit API

62 lines 2.82 kB
"use strict"; // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2022 Steadybit GmbH var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.abortExecution = abortExecution; exports.abortExecutionWithOpts = abortExecutionWithOpts; exports.abortExecutionWithError = abortExecutionWithError; exports.getExecutionErrorBody = getExecutionErrorBody; const safe_1 = __importDefault(require("colors/safe")); const util_1 = require("util"); function abortExecution(msg, ...args) { return abortExecutionWithOpts(undefined, msg, ...args); } function abortExecutionWithOpts({ colorize = true } = {}, msg, ...args) { // Make unit-testing easier by only aborting the process outside of Jest // https://jestjs.io/docs/environment-variables if (process.env.NODE_ENV !== 'test') { if (colorize) { msg = safe_1.default.red(msg); } console.error(msg, ...args); process.exit(1); } return new Error((0, util_1.format)(msg, ...args)); } function abortExecutionWithError(error, msg, ...args) { return __awaiter(this, void 0, void 0, function* () { var _a; let message = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : 'Unknown error'; const errorBody = yield getExecutionErrorBody(error); if (errorBody) { message = `${message}: ${JSON.stringify(errorBody, undefined, 2)}`; } return abortExecution(`${msg}: %s`, ...args, message); }); } function getExecutionErrorBody(error) { return __awaiter(this, void 0, void 0, function* () { var _a; if (typeof ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.json) === 'function') { try { return yield error.response.json(); } catch (_b) { // Ignore errors } } }); } //# sourceMappingURL=errors.js.map