Skip to content

Commit

Permalink
fix formatting of error msg and update test
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Nov 14, 2024
1 parent fc799e3 commit 131a4b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

import { Gui, imperative } from "@zowe/zowe-explorer-api";
import { ErrorCorrelator, Gui, imperative, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
import { AuthUtils } from "../../../src/utils/AuthUtils";
import { Constants } from "../../../src/configuration/Constants";
import { MockedProperty } from "../../__mocks__/mockUtils";
Expand All @@ -21,12 +21,23 @@ describe("AuthUtils", () => {
errorCode: 401 as unknown as string,
msg: "All configured authentication methods failed",
});
const profile = { type: "zosmf" } as any;
const profile = { name: "aProfile", type: "zosmf" } as any;
const correlateErrorMock = jest.spyOn(ErrorCorrelator.getInstance(), "correlateError");
const correlatedError = ErrorCorrelator.getInstance().correlateError(ZoweExplorerApiType.All, errorDetails, {
templateArgs: {
profileName: profile.name,
},
});
const promptForAuthenticationMock = jest
.spyOn(AuthUtils, "promptForAuthentication")
.mockImplementation(async () => Promise.resolve(true));
AuthUtils.promptForAuthError(errorDetails, profile);
expect(promptForAuthenticationMock).toHaveBeenCalledWith(errorDetails, profile);
expect(correlateErrorMock).toHaveBeenCalledWith(ZoweExplorerApiType.All, errorDetails, {
templateArgs: {
profileName: profile.name,
},
});
expect(promptForAuthenticationMock).toHaveBeenCalledWith(errorDetails, profile, correlatedError);
});
});
describe("promptForSsoLogin", () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/zowe-explorer/src/utils/AuthUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ export class AuthUtils {
(Number(err.errorCode) === imperative.RestConstants.HTTP_STATUS_401 ||
err.message.includes("All configured authentication methods failed"))
) {
void AuthUtils.promptForAuthentication(err, profile).catch((error) => error instanceof Error && ZoweLogger.error(error.message));
const correlation = ErrorCorrelator.getInstance().correlateError(ZoweExplorerApiType.All, err, {
templateArgs: {
profileName: profile.name
}
});
void AuthUtils.promptForAuthentication(err, profile, correlation).catch(
(error) => error instanceof Error && ZoweLogger.error(error.message)
);
}
}

Expand Down

0 comments on commit 131a4b5

Please sign in to comment.