Skip to content

Commit

Permalink
extend imperativeError, rename optional property
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Twydell <[email protected]>
  • Loading branch information
AndrewTwydell committed Feb 5, 2025
1 parent ac10a1a commit ee3edd1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/sdk/__tests__/__unit__/get/Get.resource.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ describe("CMCI - Get resource", () => {
expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should provide a CicsCmciRestError when requestOptions.useV4ErrorFormat is true", async () => {
it("should provide a CicsCmciRestError when requestOptions.useCICSCmciRestError is true", async () => {

getExpectStringMock.mockClear();
getExpectStringMock.mockResolvedValue(nodataXmlResponse);

endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/REGION1`;
try {
response = await getResource(dummySession, resourceParms, { useV4ErrorFormat: true });
response = await getResource(dummySession, resourceParms, { useCICSCmciRestError: true });
} catch (err) {
error = err;
}
Expand All @@ -323,14 +323,14 @@ describe("CMCI - Get resource", () => {
expect(getExpectStringMock).toHaveBeenCalledWith(dummySession, endPoint, []);
});

it("should provide a ImperativeError when requestOptions.useV4ErrorFormat is false", async () => {
it("should provide a ImperativeError when requestOptions.useCICSCmciRestError is false", async () => {

getExpectStringMock.mockClear();
getExpectStringMock.mockResolvedValue(nodataXmlResponse);

endPoint = `/${CicsCmciConstants.CICS_SYSTEM_MANAGEMENT}/${resource}/REGION1`;
try {
response = await getResource(dummySession, resourceParms, { useV4ErrorFormat: false });
response = await getResource(dummySession, resourceParms, { useCICSCmciRestError: false });
} catch (err) {
error = err;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/doc/ICMCIRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ICMCIRequestOptions {

/**
* If True, a new CicsCmciRestError is returned with formatted CMCI response codes.
* Default value is False to maintain backward compatibility.
*/
useV4ErrorFormat?: boolean;
useCICSCmciRestError?: boolean;
}
2 changes: 1 addition & 1 deletion packages/sdk/src/rest/CicsCmciRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class CicsCmciRestClient extends RestClient {
return apiResponse;
}

if (requestOptions?.useV4ErrorFormat) {
if (requestOptions?.useCICSCmciRestError) {
throw new CicsCmciRestError(CicsCmciMessages.cmciRequestFailed.message, apiResponse.response.resultsummary);
}

Expand Down
9 changes: 6 additions & 3 deletions packages/sdk/src/rest/CicsCmciRestError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
*
*/

import { ImperativeError } from "@zowe/imperative";
import { ICMCIResponseResultSummary } from "../doc";

export class CicsCmciRestError extends Error {
export class CicsCmciRestError extends ImperativeError {

resultSummary: ICMCIResponseResultSummary;

Expand All @@ -20,8 +21,10 @@ export class CicsCmciRestError extends Error {
RESPONSE_1_ALT: string;
RESPONSE_2_ALT: string;

constructor(message: string, resultSummary: ICMCIResponseResultSummary) {
super(message);
constructor(msg: string, resultSummary: ICMCIResponseResultSummary) {
super({
msg,
});
this.resultSummary = resultSummary;
this.parseResultSummary();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vsce/src/utils/profileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class ProfileManagement {
...params?.criteria && { criteria: params.criteria },
...params?.parameter && { parameter: params.parameter },
...params?.queryParams && { queryParams: params.queryParams },
}, { failOnNoData: false, useV4ErrorFormat: true });
}, { failOnNoData: false, useCICSCmciRestError: true });
return response;
}

Expand Down Expand Up @@ -418,7 +418,7 @@ export class ProfileManagement {
nodiscard: true,
overrideWarningCount: true,
}
}, { failOnNoData: false, useV4ErrorFormat: true });
}, { failOnNoData: false, useCICSCmciRestError: true });
if (response.resultsummary.api_response1 === `${CicsCmciConstants.RESPONSE_1_CODES.OK}`) {
const resultsSummary = response.resultsummary;
return { cacheToken: resultsSummary.cachetoken, recordCount: parseInt(resultsSummary.recordcount, 10) };
Expand Down

0 comments on commit ee3edd1

Please sign in to comment.