Skip to content

Commit 530ecb2

Browse files
authored
fix(launch): 外置登录令牌刷新失败时抛出异常而非静默继续 (#3307)
* fix(launch): 外置登录令牌刷新失败时抛出异常而非静默继续 McLoginRequestRefresh 在刷新令牌收到 HttpResponseException(如会话过期返回 401、服务端 5xx)时,仅弹窗提示后 return,未向上抛出。这导致 McLoginServerStart 将本次登录判为"刷新成功"(第 1420 行 return),带着未设置的空 AccessToken 继续 启动;同时也跳过了其设计中的自动恢复——首次刷新失败本应回退到普通登录(用户名/ 密码重新验证)。结果:外置(Authlib)用户会话过期时,看到错误弹窗,游戏却仍以无效 会话启动,且不会自动重新登录。 改为在该 catch 中抛出携带服务端错误详情的异常,交由上层既有逻辑处理:首次失败 回退普通登录,二次失败中止启动并提示。同时移除内层重复弹窗(上层已统一提示)。 * fix(launch): 刷新失败改为包装原异常抛出,保留状态码与堆栈 * fix(launch): 及时释放刷新失败的 Response 并兜底校验登录凭据
1 parent 8cfec15 commit 530ecb2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,10 @@ private static void McLoginServerStart(ModLoader.LoaderTask<McLoginServer, McLog
14721472
}
14731473

14741474
// 最终完成
1475+
// 兜底校验:若走到这里仍未取得有效 AccessToken(例如回退登录的 HTTP 失败被 McLoginRequestLogin
1476+
// 吞掉并返回 false),说明登录实际失败,必须中止,避免带着空凭据继续启动(见 #3307 review)。
1477+
if (string.IsNullOrEmpty(data.output.AccessToken))
1478+
throw new Exception(Lang.Text("Minecraft.Launch.Login.Failed"));
14751479
data.Progress = 0.95d;
14761480
}
14771481

@@ -1616,9 +1620,13 @@ private static void McLoginRequestRefresh(ref ModLoader.LoaderTask<McLoginServer
16161620
}
16171621
catch (HttpResponseException ex)
16181622
{
1619-
if (_TryGetLastError(ex, out var message)) ModMain.MyMsgBox(message, Lang.Text("Minecraft.Launch.Login.Failed"));
1623+
// 刷新失败必须向上抛出:否则 McLoginServerStart 会把本次登录判为“刷新成功”、带着空令牌继续
1624+
// 启动,并丧失“回退到普通登录”的自动恢复机会。保留服务端错误详情作为消息,并把原始
1625+
// HttpResponseException(含状态码/堆栈)作为 InnerException 以便诊断;同时显式 Dispose 及时
1626+
// 释放底层 Response,不依赖终结器兜底(其回收时机不确定,可能令底层资源驻留)。
1627+
var message = _TryGetLastError(ex, out var detail) ? detail : ex.Message;
16201628
ex.Dispose();
1621-
return;
1629+
throw new Exception(message, ex);
16221630
}
16231631
}
16241632

0 commit comments

Comments
 (0)