Skip to content

Commit cb25bc4

Browse files
committed
feat: When console login is not performed, throw more explicit errors and prompts
1 parent 2ed5131 commit cb25bc4

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

packages/cli/src/error-handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function alignContinuation(text: string): string {
2222

2323
function enhanceHint(err: BailianError): string | undefined {
2424
if (err.exitCode === ExitCode.AUTH) {
25-
if (err.message === CONSOLE_GATEWAY_NO_TOKEN_MESSAGE) {
25+
if (
26+
err.message === CONSOLE_GATEWAY_NO_TOKEN_MESSAGE ||
27+
err.hint?.includes("auth login --console")
28+
) {
2629
return err.hint;
2730
}
2831
return [

packages/core/src/console/gateway.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,19 @@ export async function callConsoleGateway(
7878

7979
const innerData = json.data as Record<string, unknown> | undefined;
8080
if (innerData?.success === false && innerData.errorCode) {
81+
const errorCode = String(innerData.errorCode);
82+
const notLogined = errorCode.includes("NotLogined");
83+
const errorMsg = typeof innerData.errorMsg === "string" ? innerData.errorMsg : undefined;
8184
throw new BailianError(
82-
`Console gateway error: ${innerData.errorCode}`,
83-
ExitCode.GENERAL,
84-
typeof innerData.errorMsg === "string" ? innerData.errorMsg : undefined,
85+
notLogined
86+
? "Console session is not logged in or has expired."
87+
: `Console gateway error: ${errorCode}`,
88+
notLogined ? ExitCode.AUTH : ExitCode.GENERAL,
89+
notLogined
90+
? "Run `bl auth login --console` to sign in or refresh your console session."
91+
: errorMsg && errorMsg !== errorCode
92+
? errorMsg
93+
: undefined,
8594
);
8695
}
8796

0 commit comments

Comments
 (0)