UNPKG

trm-client

Version:

TRM (Transport Request Manager) Client

89 lines (88 loc) 4.82 kB
"use strict"; 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.logError = logError; const trm_core_1 = require("trm-core"); const util_1 = require("util"); const chalk_1 = __importDefault(require("chalk")); const trm_commons_1 = require("trm-commons"); const commons_1 = require("../commands/commons"); const _getUnauthorizedError = () => { return `User "${trm_core_1.SystemConnector.getLogonUser()}" is not authorized to execute TRM RFC functions. Follow this guide https://docs.trmregistry.com/#/server/docs/setup?id=user-authorization-maintenance.`; }; function logError(err) { return __awaiter(this, void 0, void 0, function* () { var originalException; if (err.originalException) { originalException = err; while (originalException.originalException) { trm_commons_1.Logger.error((0, util_1.inspect)(originalException, { breakLength: Infinity, compact: true }), true); originalException = originalException.originalException; } } else { trm_commons_1.Logger.error((0, util_1.inspect)(err, { breakLength: Infinity, compact: true }), true); originalException = err; } var sError = (originalException.message || 'Unknown error.').trim(); var aError = []; if (originalException.name === 'ExitPromptError') { trm_commons_1.Logger.log(`User exited prompt: ${originalException.message}`, true); return; } else if (originalException.name === 'TrmRegistryError') { if (originalException.status) { sError = `${chalk_1.default.black.bgRed(originalException.status)} ${sError}`; if ((originalException.status === 401 || /whoami$/.test(originalException.axiosError.request.path)) && !commons_1.CommandContext.hasRegistryAuthData) { aError.push(`${chalk_1.default.black.bgRed(originalException.status)} You are not logged in!`); aError.push(`${chalk_1.default.black.bgRed(originalException.status)} Run command "trm login" and follow instructions.`); } } } else if (originalException.name === 'TrmRFCClient') { const rfcClientError = originalException; if (rfcClientError.exceptionType) { if (rfcClientError.exceptionType[0] === 'Z') { trm_commons_1.Logger.error(`${rfcClientError.exceptionType} ${sError}`, true); } else { sError = `${chalk_1.default.black.bgRed(rfcClientError.exceptionType)} ${sError}`; if (rfcClientError.exceptionType === "TRM_RFC_UNAUTHORIZED") { sError = chalk_1.default.black.bgRed(`${chalk_1.default.black.bgRed(rfcClientError.exceptionType)} ${_getUnauthorizedError()}`); } } } } else if (originalException.name === 'TrmRESTClient') { const restClientError = originalException; if (restClientError.exceptionType == "TRM_RFC_UNAUTHORIZED") { aError.push(chalk_1.default.black.bgRed(`${chalk_1.default.black.bgRed(restClientError.restError.status)} ${_getUnauthorizedError()}`)); } if (restClientError.restError) { if (restClientError.restError.status === 404) { aError.push(`${chalk_1.default.black.bgRed(restClientError.restError.status)} Service cannot be reached (Check if trm-rest is installed and activated correctly).`); } sError = `${chalk_1.default.black.bgRed(restClientError.restError.status)} ${sError}`; } } if (sError) { trm_commons_1.Logger.error(sError); } aError.forEach(message => { if (message) { trm_commons_1.Logger.error(message); } }); }); }