Skip to content

Commit

Permalink
refactor: add login error category
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolang124 committed Apr 28, 2024
1 parent 8d76945 commit 71595c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/fx-core/src/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "./m365";
export * from "./script";
export * from "./upgrade";
export * from "./yml";
export * from "./types";
15 changes: 8 additions & 7 deletions packages/vscode-extension/src/commonlib/codeFlowLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { env, Uri } from "vscode";
import { randomBytes } from "crypto";
import { getExchangeCode } from "./exchangeCode";
import * as os from "os";
import { ErrorCategory } from "@microsoft/teamsfx-core";
interface Deferred<T> {
resolve: (result: T | Promise<T>) => void;
reject: (reason: any) => void;
Expand Down Expand Up @@ -177,14 +178,14 @@ export class CodeFlowLogin {
} else {
this.status = loggedOut;
}
deferredRedirect.reject(
new UserError(
getDefaultString("teamstoolkit.codeFlowLogin.loginComponent"),
getDefaultString("teamstoolkit.codeFlowLogin.loginTimeoutTitle"),
getDefaultString("teamstoolkit.codeFlowLogin.loginTimeoutDescription"),
localize("teamstoolkit.codeFlowLogin.loginTimeoutDescription")
)
const err = new UserError(
getDefaultString("teamstoolkit.codeFlowLogin.loginComponent"),
getDefaultString("teamstoolkit.codeFlowLogin.loginTimeoutTitle"),
getDefaultString("teamstoolkit.codeFlowLogin.loginTimeoutDescription"),
localize("teamstoolkit.codeFlowLogin.loginTimeoutDescription")
);
err.categories = [ErrorCategory.Internal];
deferredRedirect.reject(err);
}, 5 * 60 * 1000); // keep the same as azure login

function cancelCodeTimer() {
Expand Down
13 changes: 7 additions & 6 deletions packages/vscode-extension/src/debug/prerequisitesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { vscodeTelemetry } from "./depsChecker/vscodeTelemetry";
import { localTelemetryReporter } from "./localTelemetryReporter";
import { ProgressHelper } from "./progressHelper";
import { allRunningTeamsfxTasks, terminateAllRunningTeamsfxTasks } from "./teamsfxTaskHandler";
import { ErrorCategory } from "@microsoft/teamsfx-core";

enum Checker {
M365Account = "Microsoft 365 Account",
Expand Down Expand Up @@ -411,13 +412,13 @@ function ensureM365Account(
}
if (token === undefined) {
// corner case but need to handle
return err(
new SystemError(
ExtensionSource,
ExtensionErrors.PrerequisitesNoM365AccountError,
"No Microsoft 365 account login"
)
const e = new SystemError(
ExtensionSource,
ExtensionErrors.PrerequisitesNoM365AccountError,
"No Microsoft 365 account login"
);
e.categories = [ErrorCategory.Internal];
return err(e);
}
const loginHint = typeof upn === "string" ? upn : undefined;
const tenantId = typeof tid === "string" ? tid : undefined;
Expand Down

0 comments on commit 71595c5

Please sign in to comment.