automatic loader without
promise
injection intocatch
自动为promise注入catch,捕获错误的loader
npm i promise-add-catch-loader -D
# or
yarn add promise-add-catch-loader -D
before:
function axios (){
return new Promise((resolve,reject)=>{
resolve('test')
})
}
axios.then(res=>{
console.log('test1');
})
after:
function axios (){
return new Promise((resolve,reject)=>{
resolve('test')
})
}
axios.then(res=>{
console.log('test1');
}).catch(err=>{
console.error(err)
})
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
{
+ loader:'promise-add-catch-loader',
+ options:{
+ catchCode:"console.log(err.message)" // 选填参数,不传默认console.error(err)
+ }
}
]
}
]
}
}
key(键) | value(值) | Default(默认值) | remarks(备注) |
---|---|---|---|
catchCode | string | console.error(err) | catch回调中逻辑代码 |