Skip to content

Commit

Permalink
исправляет ошибки в then
Browse files Browse the repository at this point in the history
  • Loading branch information
Suninall committed Dec 30, 2024
1 parent b8ee237 commit b4c5064
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions js/interact-with-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ const getData = (onSuccess, onError) => () =>
credentials: "same-origin",
},
)
.then((response) => {
.then((response, data) => {
if (response.ok) {
return response.json();
}else{
onError("Не удалось загрузить данные. Попробуйте ещё раз");
}

throw new Error(`${response.status} ${response.statusText}`);
})
.then((data) => {
onSuccess(data);

})
.catch(() => {
onError("Не удалось загрузить данные. Попробуйте ещё раз");
Expand Down
4 changes: 2 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "./form-filling.js";
import {loadPhoto} from "./photo-load.js";
import {getData} from "./interact-with-data.js";
loadPhoto();
const loadAnimals = getData(renderPosts, showAlert);
loadAnimals();
const loadData = getData(renderPosts, showAlert);
loadData();

//const sendData = postData(console.log, console.error);
//sendData();

0 comments on commit b4c5064

Please sign in to comment.