@zowe/cli
Version:
Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.
77 lines • 3.16 kB
JavaScript
;
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
const imperative_1 = require("@zowe/imperative");
const util_1 = require("util");
const ZosmfHeaders_1 = require("./ZosmfHeaders");
/**
* Wrapper for invoke z/OSMF API through the RestClient to perform common error
* handling and checking and resolve promises according to generic types
* @export
* @class ZosmfRestClient
* @extends {RestClient}
*/
class ZosmfRestClient extends imperative_1.RestClient {
/**
* Use the Brightside logger instead of the imperative logger
* @type {Logger}
*/
get log() {
return imperative_1.Logger.getAppLogger();
}
/**
* Append z/OSMF specific headers to the callers headers for cases
* where a header is common to every request.
* @param {any[] | undefined} headers - current header array
* @memberof ZosmfRestClient
*/
appendHeaders(headers) {
if (util_1.isNullOrUndefined(headers)) {
return [ZosmfHeaders_1.ZosmfHeaders.X_CSRF_ZOSMF_HEADER];
}
else {
headers.push(ZosmfHeaders_1.ZosmfHeaders.X_CSRF_ZOSMF_HEADER);
return headers;
}
}
/**
* Process an error encountered in the rest client
* @param {IImperativeError} original - the original error automatically built by the abstract rest client
* @returns {IImperativeError} - the processed error with details added
* @memberof ZosmfRestClient
*/
processError(original) {
original.msg = "z/OSMF REST API Error:\n" + original.msg;
let details = original.causeErrors;
try {
const json = JSON.parse(details);
// if we didn't get an error trying to parse json, check if there is a stack
// on the JSON error and delete it
if (json.stack != null) {
this.log.error("An error was encountered in z/OSMF with a stack." +
" Here is the full error before deleting the stack:\n%s", JSON.stringify(json));
this.log.error("The stack has been deleted from the error before displaying the error to the user");
delete json.stack; // remove the stack field
}
// if we didn't get an error, make the parsed details part of the error
details = imperative_1.TextUtils.prettyJson(json, undefined, false);
}
catch (e) {
// if there's an error, the causeErrors text is not json
this.log.debug("Encountered an error trying to parse causeErrors as JSON - causeErrors is likely not JSON format");
}
original.msg += "\n" + details; // add the data string which is the original error
return original;
}
}
exports.ZosmfRestClient = ZosmfRestClient;
//# sourceMappingURL=ZosmfRestClient.js.map