Tag Archives: Uncaught (in promise) error

How to Solve Uncaught (in promise) Error (Two Solutions)

Reporting an uncaught (in promise) error. The solution
There are two Solutions:

1. when using Axios to request an interface, add catch() behind then():

  1. export function stopMCUMixTranscode(params) {
    return new Promise((resolve, reject) => {
    axios
    .post(********, params)
    .then((res) => {
    resolve(res)
    })
    .catch((err) => {
    reject(err)
    })
    })
    }

     

2. Use return promise Reject (new error (res.msg | ‘error’)) to catch and handle exceptions. It needs to be use .catch(err=>{console.log(err)}) to catch exceptions when the request comes back,

return Promise.reject(error).catch(err=>{console.log(err)}) // Return the error message returned by the interface

How to solve Uncaught (in promise) error in VUE?

When writing the vue project interface today, there was an Uncaught (in promise) error error.

 

 

 

I took a closer look, the interface is ok,

 

 

 

Me where the problem seems to have nothing, why the console which will be reported this wrong?

 

Later I found out that I did not write catch and he forcibly threw the error, so I changed the code to the following.

 

 

 

 

But after the change, it did not report the Uncaught (in promise) error error, and the other errors were reported, and a bunch of such errors were reported ↓

 

 

 

 

 

Reported so many mistakes, almost forced me. (But don’t panic, raise Erlang’s legs, drink a glass of water, and continue to look down)

 

 

      .catch(err=>{
this.$message.error(err.message);
console.log(err);
})

 

Just write message after err.