i have code something similar like this
fetch("http://httpstat.us/401", {
method: 'GET',
headers: {
"Accept": "application/json",
"Accept-Language": "en-US",
"Content-Type": "application/json",
"token": localStorage.getItem('access_token')
}
}
).then(response =>{
if(response.ok){
return Promise.resolve(response.json())
}
else {
return Promise.reject();
}
}
}
)
so in my headers if i wont send the token
or say localstorage
is not having access_token
or it is empty
then from server 401 error
is thrown in the console,
can any body please give me a way so that i can handle the error and it is not thrown in the console
And i don't want a solution like this because it is a simple hack which programmer dose it for his satisfaction , how can we tell the client to do all this kind of stuff. so i want a programmatic solution to avoid this.