Is there a way to retrieve the actual error text in JavaScript when an error occurs on XMLHttpRequest? Even though it gets displayed in the console, it's challenging to access as a string.
For example:
var req = new XMLHttpRequest();
req.open('get', 'http://nowhere/', true);
req.send();
The following error message appears in the console:
GET http://nowhere/ net::ERR_NAME_NOT_RESOLVED
How can this be obtained using JavaScript?
Edit: Just to clarify, I specifically want to know how to handle network errors, such as cases where there is no response due to various reasons. This includes situations like when the host name cannot be resolved, the connection is refused, or when there is a CORS error.