I have this code to check if there is a file with the given URL in the server or not. it returns true if there is a file and false if else...
The issue is if there is not a file, in the chrome's console I can see a 404 error which I expect because the given URL doesn't exist But:
I wonder if this error will affect the execution of the whole code and the code quality?!
How to remove the error if there is any solution?
// Check if file exist in the server
function fileExist(url) {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('HEAD', url, true);
xhr.onload = function () {
return resolve(xhr.status==200)
};
xhr.onerror = function () {
return resolve(xhr.status==200)
};
xhr.send();
});
}