I have a code:
function () {
return new Promise((resolve, reject) => {
try {
fetch(URL, { method: METHOD, body: BODY })
.then((res) => res.json())
.then((json) => {
resolve(json);
})
.catch((res) => {
reject(res);
})
} catch (exception) {
reject(exception);
}
});
}
When server responses not with json I've got
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
I know that try-catch do not catch async throws.
I have read
Cannot catch UnhandledPromiseRejectionWarning in promise,
Try Catch unable to catch UnhandledPromiseRejectionWarning,
“UnhandledPromiseRejectionWarning” error even when catch is present
but there is no answer for my question.