feat: When console login is not performed, throw more explicit errors and prompts

This commit is contained in:
qcq01083097
2026-06-16 15:11:10 +08:00
parent 2ed513124e
commit cb25bc4149
2 changed files with 16 additions and 4 deletions
+4 -1
View File
@@ -22,7 +22,10 @@ function alignContinuation(text: string): string {
function enhanceHint(err: BailianError): string | undefined {
if (err.exitCode === ExitCode.AUTH) {
if (err.message === CONSOLE_GATEWAY_NO_TOKEN_MESSAGE) {
if (
err.message === CONSOLE_GATEWAY_NO_TOKEN_MESSAGE ||
err.hint?.includes("auth login --console")
) {
return err.hint;
}
return [
+12 -3
View File
@@ -78,10 +78,19 @@ export async function callConsoleGateway(
const innerData = json.data as Record<string, unknown> | undefined;
if (innerData?.success === false && innerData.errorCode) {
const errorCode = String(innerData.errorCode);
const notLogined = errorCode.includes("NotLogined");
const errorMsg = typeof innerData.errorMsg === "string" ? innerData.errorMsg : undefined;
throw new BailianError(
`Console gateway error: ${innerData.errorCode}`,
ExitCode.GENERAL,
typeof innerData.errorMsg === "string" ? innerData.errorMsg : undefined,
notLogined
? "Console session is not logged in or has expired."
: `Console gateway error: ${errorCode}`,
notLogined ? ExitCode.AUTH : ExitCode.GENERAL,
notLogined
? "Run `bl auth login --console` to sign in or refresh your console session."
: errorMsg && errorMsg !== errorCode
? errorMsg
: undefined,
);
}