I tried to find out the solution for one of the existing question
Error Handling in HTTP Ajax Call using $fetch Javascript - I tried to reproduce the said scenario. I found the issue, that is the HTTP call triggers the HTTP OPTIONS
method. Finally its not returning any HTTP Status code. I checked the Netwok, its shows an empty status code and the status signal is grayed
Refer Preflight Table Request: https://docs.microsoft.com/en-us/rest/api/storageservices/preflight-table-request
Kindly assist me how to handle the failure of HTTP OPTIONS
I tried the following code
$fetch("http://localhost:1000/SearchUsers?....")
.then(response => {
if((response != undefined) && (response != null)) {
if (response.status && (response.status === 200)) {
alert('Super');
return response.json();
} else {
alert('Hai');
return '';
}
} else {
alert('Oooops');
return '';
}
})
.catch(err => {
const errStatus = err.response ? err.response.status : 500;
if (errStatus === 404){
alert("HTTP 404");
} else {
alert("Network or Internal Server Error");
}
});
The above said code always executes the Catch
block and it alerts the message "Network or Internal Server Error"
.
I tried with following Header information too, but it fails.
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Methods': 'POST, GET, PUT'
}
Kindly assist me how to get the appropriate Error Status Code, in current scenario the requesting server is offline.