Answer the question
In order to leave comments, you need to log in
How can I track fetch whether json response came or not?
const request = await fetch(url, {
method: 'POST'
});
if (request.ok) {
const response = await request.json();
} else {
console.log('Ошибка сервера');
}
Answer the question
In order to leave comments, you need to log in
probably request.json()
throw up with an error if not JSON was returned there.
Therefore, it is enough to wrap in try..catch:
let response;
try {
response = await request.json();
} catch (err) {
console.error(err);
return;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question