fix:API响应code=200时显示msg,非200抛出msg错误

This commit is contained in:
97694732@qq.com 2026-06-05 14:10:53 +08:00
parent fe49ca79ae
commit 5de0c69c94

View File

@ -2065,7 +2065,19 @@ export default {
uni.hideLoading() uni.hideLoading()
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
throw new Error('API返回: HTTP ' + res.statusCode + ' ' + JSON.stringify(res.data || '')) throw new Error('API返回: HTTP ' + res.statusCode)
}
// JSON
var respData = res.data
if (typeof respData === 'string') {
try { respData = JSON.parse(respData) } catch (e) { respData = { code: 500, msg: respData } }
}
if (respData && respData.code === 200) {
uni.showToast({ title: respData.msg || '上传成功', icon: 'success' })
} else {
throw new Error(respData && respData.msg || '上传失败')
} }
// //