Repository navigation
fix(catalog): 目录响应缺字段时报错,不再静默变成空目录 - #102
Open
std-external wants to merge 1 commit into
Open
std-external wants to merge 1 commit into
std-external wants to merge 1 commit into
Conversation
上游把返回体的字段改名或漏掉时,前端原来用「不是数组就当空数组」兜底, 结果和「目录里真的没有 Mod」长得一模一样:列表空、没有错误、日志里也 什么都没有(今天镜像只剩 1 条时就是这个观感)。 现在把返回体解析抽成 parseCatalogResponse:data 不是数组、code 不是 200、 或根本不是 JSON 时直接抛错。界面上会走现有的「加载失败,请重试」,错误 也会经前端日志落盘,能看出是哪一侧出了问题,不用再靠猜。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
今天镜像的 Mod 目录接口在 HTTP 200、结构正常、只是数据变少/字段变化时,客户端表现得和「目录里真的没有 Mod」完全一样:筛选空、没有报错、日志里也查不到任何东西。
代码里的兜底就是这一行(
src/celemod-ui/src/api/modCatalog.ts):只要上游把返回体的
data(或整体 JSON 形状)改掉,前端就静默当成空目录,用户和排查的人都拿不到任何线索——今天排查时只能靠逐层手抓接口才定位到是上游数据的问题。改动
把返回体解析抽到
src/api/catalogResponse.ts的parseCatalogResponse:data不是数组 → 抛错并带上code/message;code存在且不是 200 → 抛错并带上理由;界面会走现有的「加载失败,请重试」,错误也会经前端日志(
logging.ts的 console 转发)落盘,能直接看出是哪一侧的问题。验证
src/api/catalogResponse.test.ts(5 个用例:正常、空目录、缺data、code非 200、非 JSON),node --import tsx --test src/api/catalogResponse.test.ts全过;tsc --noEmit通过;说明
这次事故本身是上游数据问题(镜像那边已确认是上游字段改名,客户端不需要跟着改);这个 PR 只是把「同样的上游变化下次发生时能报出来」,不改变目录接口的语义。