Skip to content

Commit 3522aed

Browse files
committed
update fetch helper functions
1 parent 1297d5c commit 3522aed

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,33 @@ const resolvers = {
4949

5050
function fetchTrainings() {
5151
// More info about the fetch function? https://github.com/bitinn/node-fetch#json
52-
return fetch("https://restapi.reactgraphql.academy/v1/trainings/").then(res =>
53-
res.json()
54-
);
52+
return fetch("https://restapi.reactgraphql.academy/v1/trainings/")
53+
.then(res => res.json())
54+
.catch(error => console.log(error));
5555
}
5656

5757
function fetchTrainingById(id) {
58-
return fetch(
59-
`https://restapi.reactgraphql.academy/v1/trainings/${id}`
60-
).then(res => res.json());
58+
return fetch(`https://restapi.reactgraphql.academy/v1/trainings/${id}`)
59+
.then(res => res.json())
60+
.catch(error => console.log(error));
6161
}
6262

6363
function fetchDiscounts() {
64-
return fetch("https://restapi.reactgraphql.academy/v1/discounts/").then(res =>
65-
res.json()
66-
);
64+
return fetch("https://restapi.reactgraphql.academy/v1/discounts/")
65+
.then(res => res.json())
66+
.catch(error => console.log(error));
6767
}
6868

6969
function fetchTrainingByUrl(url) {
70-
return fetch(url).then(res => res.json());
70+
return fetch(url)
71+
.then(res => res.json())
72+
.catch(error => console.log(error));
7173
}
7274

7375
function fetchDiscountById(id) {
74-
return fetch(
75-
`https://restapi.reactgraphql.academy/v1/discounts/${id}`
76-
).then(res => res.json());
76+
return fetch(`https://restapi.reactgraphql.academy/v1/discounts/${id}`)
77+
.then(res => res.json())
78+
.catch(error => console.log(error));
7779
}
7880

7981
function fetchDiscountByUrl(url) {

0 commit comments

Comments
 (0)