const asyncHandle = (promise) => {
if (!promise || !promise.then) {
return new Promise((resolve, reject) => {
reject(new Error("requires promises as the param"));
}).catch((err) => {
return [err, null];
});
}
return promise.then(function () {
return [null, ...arguments];
}).catch(err => {
return [err, null];
});
};
let [err,data] = asyncHandle(func());
封装promise以在async/await下处理错误信息
最新推荐文章于 2024-03-01 10:09:24 发布