提交 fa57284f authored 作者: 周盛's avatar 周盛

为request.js 添加错误弹窗处理函数

上级 5b0536fa
...@@ -44,6 +44,7 @@ function checkStatus(response) { ...@@ -44,6 +44,7 @@ function checkStatus(response) {
* @return {object} An object containing either "data" or "err" * @return {object} An object containing either "data" or "err"
*/ */
export default function request(url, options, config = {enableLoading: true}) { export default function request(url, options, config = {enableLoading: true}) {
const { errorHandle } = config; // 错误弹窗 回调
const defaultOptions = { const defaultOptions = {
credentials: 'omit', credentials: 'omit',
mode: 'cors', mode: 'cors',
...@@ -96,7 +97,7 @@ export default function request(url, options, config = {enableLoading: true}) { ...@@ -96,7 +97,7 @@ export default function request(url, options, config = {enableLoading: true}) {
if (xxx.errMsg) { if (xxx.errMsg) {
Toast.hide(); Toast.hide();
Modal.alert('', `${xxx.errMsg}`, [ Modal.alert('', `${xxx.errMsg}`, [
{ text: '知道了', onPress: () => console.log('ok') }, { text: '知道了', onPress: errorHandle ? ()=>errorHandle(xxx) : () => console.log('ok') },
]); ]);
return; return;
} }
...@@ -106,7 +107,7 @@ export default function request(url, options, config = {enableLoading: true}) { ...@@ -106,7 +107,7 @@ export default function request(url, options, config = {enableLoading: true}) {
}else if(response && (response.errMsg || response.errmsg)){ }else if(response && (response.errMsg || response.errmsg)){
Toast.hide(); Toast.hide();
Modal.alert('', `${response.errMsg || response.errmsg}`, [ Modal.alert('', `${response.errMsg || response.errmsg}`, [
{ text: '知道了', onPress: () => console.log('ok') }, { text: '知道了', onPress: errorHandle ? ()=>errorHandle(response) : () => console.log('ok') },
]); ]);
return; return;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论