This commit is contained in:
Valeria Fadeeva 2023-12-10 01:37:11 +05:00
parent d3c9a28c3b
commit a7cb70c211
1 changed files with 5 additions and 2 deletions

View File

@ -78,10 +78,11 @@ async function bodyFetch(url) {
let response = await fetch(tplUrl);
let body = document.getElementById('body');
if(tplUrl == 'news.tpl.html') {let res = await fetchData();}
if (response.ok) { // если HTTP-статус в диапазоне 200-299
// получаем тело ответа (см. про этот метод ниже)
let text = await response.text();
if (tplUrl == 'news.tpl.html') {await fetchData();}
body.innerHTML = text;
} else {
body.innerHTML = "Ой всё сломалось :(";
@ -139,10 +140,12 @@ let fetchPage = async function(evt) {
const linkText = this.text.trim();
const title = document.title + ": " + linkText;
if (tplUrl == 'news.tpl.html') {let res = await fetchData();}
try {
const response = await fetch(tplUrl, { signal });
text = await response.text();
if (tplUrl == 'news.tpl.html') {await fetchData();}
} catch (error) {
// DOMException: The user aborted a request.
console.log('Error: ', error)