fix(档案): 保存资料失败要提示 —— 配合后端「先推上游、失败即 400 不落库」(v26092204)

后端方案 A:PUT /profile 改预产期/昵称时先推上游用户中心,推失败返回 400 且不落库。
原来这里 .then() 不看响应、.catch() 静默 —— 用户会以为保存成功,下次加载被上游值覆盖回去
("改了没生效")。现在:非 200 或网络失败都 toast 提示,且不触发 bustReload。

- §4 硬约定新增第 9 条,说明这个接口的失败语义,避免以后又把失败吞掉
- 版本 v26092203 → v26092204
This commit is contained in:
2026-09-22 13:23:06 +08:00
parent d77b163b1a
commit 4c4c00f636
3 changed files with 18 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26092203';
var VER = '26092204';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -1245,10 +1245,20 @@
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
}).then(function () {
}).then(function (r) {
return r.json().catch(function () { return null; });
}).then(function (res) {
/* ⚠️ 2026-09-22(档案以上游为准):预产期/昵称会**先推上游、推失败后端返回 400 且不落库**。
这里必须让用户看见失败 —— 静默的话下次加载会被上游值覆盖回去,用户以为"改了没生效"。 */
if (!res || res.code !== 200) {
toast((res && res.message) || '保存失败,请检查网络后重试');
return;
}
/* 新用户首次完善资料:重载页面 → pregnancy 出真实孕周 */
if (_wasEmpty) setTimeout(bustReload, 700);
}).catch(function () { /* 保持本地值 */ });
}).catch(function () {
toast('保存失败,请检查网络后重试');
});
}
var newAvatarFile = (avFile.files && avFile.files[0]) || null;
if (newAvatarFile && avBig.classList.contains('has-img')) {