UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throw

刚写了一个异步请求,报错如下:

UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().

原因:没有进行promise的差错处理

解决方案:加一个catch语句

.catch(err => {
                console.log(err);
            })

解决!!!

你可能感兴趣的:(错误处理,bug,javascript,js)