Unhandled promise rejection error resolution

Phenomenon: The background data is returned normally, but the front-end promise processing reports an error.

 reason:

I checked the encapsulated request of request.js and found that when the status code of the background request is not 200, an error message will be rejected.

 The reject function does not go into the promise's then callback, but into the catch callback. Let's take a look at the request call.

It can be seen that the error message is not caught when using the request, so when the status returned by the background data is not 200, the error message cannot be captured, and naturally the console will report an error.

Solution: catch error messages 

 After adding the catch callback, the console will no longer report errors, which is a perfect solution.

Guess you like

Origin blog.csdn.net/baidu_36095053/article/details/125869396