catch里面回调函数为什么提示不是一个函数?请求接口最后也会进来catch回调里面,不知为啥会报错
Uncaught (in promise) TypeError: catchCallback is not a function
//fetchEX.js
export function fetchPost(url, json, callback, catchCallback) {
fetch(url,
{
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'username': cookie('username'),
'token': cookie('token'),
},
body: json,
})
.then(response => {
if (response.ok) return response.json();
else return Promise.reject(response);
}
)
.then(data => callback(data))
.catch(err => {
console.log(err,'err')//TypeError: Failed to fetch
return catchCallback(err)//Uncaught (in promise) TypeError: catchCallback is not a function
});
}
export function fetchMs(url, json, callback, catchCallback) {
fetchPost(`http://$xxx.xx.xx.xx:10034` + url, JSON.stringify(json), callback, catchCallback);
}
//index.js
fetchMs("/xxx/xxxx/xxx/xxx", {
moduleId: 'xxx',
}, res => {
},(error) => {
console.log(error,'==test')//同样进来也会打印出 TypeError: Failed to fetch
});
写发改成如下
catchCallback && catchCallback()
或者
catchCallback 参数这是默认为一个function