I encountered an issue with my api call – the server returned a 500 error. I was hoping to handle this error within a Promise, but instead, I received a runtime error TypeError: Failed to fetch
, along with a stack trace which prevented me from retrieving the status code. Is there a way for me to access the Response Instance from the api request that includes the status field without encountering a runtime error?
try {
window.fetch(url, {
method: 'POST',
body,
}).then((res) => {
// I am expecting the response here
}, (rej) => {
// Or here
});
} catch (e) {
// In cases where the server responds with a 500 error, it gets handled at this level and not inside the promise block
}