import { IImperativeError , Logger , RestClient , TextUtils , RestConstants , SessConstants , AbstractSession } from "@zowe/imperative" ; import { ZosmfHeaders } from "./ZosmfHeaders" ; export class extends RestClient export class ZosmfRestClient extends RestClient { param mSession constructor ( mSession ) { super ( mSession ) ; this . mDecode = true ; } type { Logger } public get log ( ) : Logger { return Logger . getAppLogger ( ) ; } param { any [ ] | undefined } headers memberof protected appendHeaders ( headers ) { if ( headers == null ) { headers = [ ZosmfHeaders . X_CSRF_ZOSMF_HEADER ] ; } else { headers . push ( ZosmfHeaders . X_CSRF_ZOSMF_HEADER ) ; } return headers ; } param { IImperativeError } original returns { IImperativeError } memberof protected processError ( original ) { original . msg = "z/OSMF REST API Error:\n" + original . msg ; let details = original . causeErrors ; try { const json = JSON . parse ( details ) ; 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 ; } details = TextUtils . prettyJson ( json , undefined , false ) ; } catch ( e ) { this . log . debug ( "Encountered an error trying to parse causeErrors as JSON  - causeErrors is likely not JSON format" ) ; } original . msg += "\n" + details ; if ( this . response && this . response . statusCode === RestConstants . HTTP_STATUS_401 ) { original . msg = "This operation requires authentication.\n\n" + original . msg + "\nHost:      " + this . session . ISession . hostname + "\nPort:      " + this . session . ISession . port + "\nBase Path: " + this . session . ISession . basePath + "\nResource:  " + this . mResource + "\nRequest:   " + this . mRequest + "\nHeaders:   " + JSON . stringify ( this . mReqHeaders ) + "\nPayload:   " + this . mRequest + "\n" ; if ( this . session . ISession . type === SessConstants . AUTH_TYPE_BASIC ) { original . additionalDetails = "Username or password are not valid or expired.\n\n" ; } if ( this . session . ISession . type === SessConstants . AUTH_TYPE_TOKEN ) { original . additionalDetails = "Token is not valid or expired.\n\n" + "For CLI usage, see `zowe auth login apiml --help`" ; } if ( this . session . ISession . type === SessConstants . AUTH_TYPE_CERT_PEM ) { original . additionalDetails = "Certificate is not valid or expired.\n\n" ; } } return original ; } }