![]() If an error is generated by an asynchronous module in try, catch will not catch it, for example. We can know that the xhr request generated a request error by listening to xhr.onerror. ![]() Of course, this doesn’t mean that the front-end doesn’t know that a cross-domain error was generated. But you can’t trot out the error with try-catch. ![]() However, I didn’t want to show it to the caller in the first place, because I had already set up a tuck-in solution. Previously, when I was doing canvas compositing, the domain name of some images did not support cross-domain, so I wanted to request the image directly first, and if the image was cross-domain, then request the backend interface, which would convert the image to base64, but in the process of testing, I found that this cross-domain error would definitely be shown. So it is recommended to write Promise with catch () on it, otherwise uncaught exceptions will bubble up to the global level. Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resourceĪs we can see in the image, the request for the interface is generating a cross domain error, but it’s not going to catch. One great advantage of Promise is that it comes with an exception catch method catch () that automatically goes to the catch () method when the then () method generates an error that prevents the code from running.
0 Comments
Leave a Reply. |