feat(utils): 添加响应数据错误处理逻辑
当 useResponseData 为 true 时,如果返回的 data.code 不等于 0, 则抛出包含错误信息的异常,确保错误能够被正确捕获和处理。
This commit is contained in:
parent
79a2569146
commit
50d8d1e992
|
|
@ -58,6 +58,9 @@ service.interceptors.response.use(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (response.config.useResponseData) {
|
if (response.config.useResponseData) {
|
||||||
|
if (data.code !== 0) {
|
||||||
|
throw new Error(data.data?.message || data.msg)
|
||||||
|
}
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
return response.config.useHeader ? response : data
|
return response.config.useHeader ? response : data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue