Uncaught (in promise) Error

The solution to the Uncaught (in promise) Error error
is basically due to the use of promise. I will record my solution below. There are two situations.

  1. When using the axios request interface, add catch() after then()
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. When the request comes back, you need to use .catch(err=>{console.log(err)}) to catch the exception.

return Promise.reject(error).catch(err=>{
    
    console.log(err)}) // 返回接口返回的错误信息

Guess you like

Origin blog.csdn.net/wh13821662259/article/details/117986956