Here is the code in question:
new Promise((resolve, reject) => { const opts = { credentials: 'same-origin', }; fetch(`/_api/myAPI`, opts) .then((res) => { if (!res.ok) { reject(res); } else { ...
If the URL throws an exception 401 when execution reaches reject(res); , it issues Uncaught (in promise)
Even after adding .catch after calling .then , i.e.
fetch(`/_api/myAPI`, opts) .then((res) => { if (!res.ok) { reject(res); } else { ... }) .catch((e) => { console.log(e); }
this is still happening.
Why reject will throw this exception and how to fix it? My experience is limited to jQuery.Promise , and I do not reject inside the crash handler will cause this error.
source share