feat: 接口错误处理增强,统一打印并展示后端错误信息

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-09-01 16:57:28 +08:00
co-authored by Claude Sonnet 4.6
parent 85523109f6
commit 8d69249147
6 changed files with 31 additions and 20 deletions
@@ -135,8 +135,9 @@ Component({
})) }))
this.setData({ members }) this.setData({ members })
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '加载失败', icon: 'none' }) console.error('[selectMemberDrawer] 加载成员失败:', err)
wx.showToast({ title: err?.msg || err?.message || '加载失败', icon: 'none' })
}) })
.finally(() => { .finally(() => {
wx.hideLoading() wx.hideLoading()
@@ -159,8 +160,9 @@ Component({
})) }))
this.setData({ members }) this.setData({ members })
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '加载失败', icon: 'none' }) console.error('[selectMemberDrawer] 加载成员失败:', err)
wx.showToast({ title: err?.msg || err?.message || '加载失败', icon: 'none' })
}) })
.finally(() => { .finally(() => {
wx.hideLoading() wx.hideLoading()
+6 -4
View File
@@ -101,8 +101,9 @@ Page({
}) })
} }
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '加载用户信息失败', icon: 'none' }) console.error('[addUser] 加载用户信息失败:', err)
wx.showToast({ title: err?.msg || err?.message || '加载用户信息失败', icon: 'none' })
}) })
}, },
@@ -378,8 +379,9 @@ Page({
prevPage?._loadMembers?.() prevPage?._loadMembers?.()
setTimeout(() => wx.navigateBack(), 1500) setTimeout(() => wx.navigateBack(), 1500)
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '添加失败,请重试', icon: 'none' }) console.error('[addUser] 添加用户失败:', err)
wx.showToast({ title: err?.msg || err?.message || '添加失败,请重试', icon: 'none' })
}) })
}, },
}) })
+3 -2
View File
@@ -199,8 +199,9 @@ Page({
hasMore: allRecords.length < this.data.total, hasMore: allRecords.length < this.data.total,
}) })
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '加载失败,请重试', icon: 'none' }) console.error('[data] 加载历史数据失败:', err)
wx.showToast({ title: err?.msg || err?.message || '加载失败,请重试', icon: 'none' })
}) })
.finally(() => { .finally(() => {
wx.hideLoading() wx.hideLoading()
+1
View File
@@ -32,6 +32,7 @@ Page({
wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' }) wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' })
} }
}).catch((err) => { }).catch((err) => {
console.error('[login] 登录失败:', err)
wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' }) wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' })
}).finally(() => { }).finally(() => {
this.setData({ loading: false }) this.setData({ loading: false })
@@ -149,8 +149,9 @@ Page({
}).then((res) => { }).then((res) => {
wx.setStorageSync('userInfo', res.result) wx.setStorageSync('userInfo', res.result)
wx.switchTab({ url: '/pages/home/home' }) wx.switchTab({ url: '/pages/home/home' })
}).catch(() => { }).catch((err: any) => {
wx.showToast({ title: '保存失败,请重试', icon: 'none' }) console.error('[supplementPersonal] 保存失败:', err)
wx.showToast({ title: err?.msg || err?.message || '保存失败,请重试', icon: 'none' })
}) })
}, },
}) })
@@ -167,8 +167,9 @@ Page({
hasData: list.length > 0, hasData: list.length > 0,
}) })
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '加载用户列表失败', icon: 'none' }) console.error('[userManagement] 加载用户列表失败:', err)
wx.showToast({ title: err?.msg || err?.message || '加载用户列表失败', icon: 'none' })
}) })
}, },
@@ -295,8 +296,9 @@ Page({
// 先读设备端主用户列表,判断设备是否已有主用户 // 先读设备端主用户列表,判断设备是否已有主用户
leFuService.fetchDeviceUserIds() leFuService.fetchDeviceUserIds()
.then((deviceUserIds) => this._syncUsers(pendingUsers, deviceUserIds)) .then((deviceUserIds) => this._syncUsers(pendingUsers, deviceUserIds))
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '读取设备用户失败', icon: 'none' }) console.error('[userManagement] 读取设备用户失败:', err)
wx.showToast({ title: err?.message || '读取设备用户失败', icon: 'none' })
}) })
}, },
@@ -414,8 +416,9 @@ Page({
wx.showToast({ title: '删除成功', icon: 'success' }) wx.showToast({ title: '删除成功', icon: 'success' })
this._loadMembers() this._loadMembers()
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '删除失败,请重试', icon: 'none' }) console.error('[userManagement] 删除成员失败:', err)
wx.showToast({ title: err?.msg || err?.message || '删除失败,请重试', icon: 'none' })
}) })
}, },
}) })
@@ -452,8 +455,9 @@ Page({
wx.showToast({ title: '添加成功', icon: 'success' }) wx.showToast({ title: '添加成功', icon: 'success' })
this._loadMembers() this._loadMembers()
}) })
.catch(() => { .catch((err: any) => {
wx.showToast({ title: '添加失败,请重试', icon: 'none' }) console.error('[userManagement] 添加本人失败:', err)
wx.showToast({ title: err?.msg || err?.message || '添加失败,请重试', icon: 'none' })
}) })
}, },