Skip to content

Commit ecd2acb

Browse files
committed
final
1 parent 06f5db0 commit ecd2acb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

error-handling-01/script.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ const displayCountries = function (data, className = '') {
2323
</article>
2424
`;
2525
countriesContainer.insertAdjacentHTML('beforeend', html);
26-
countriesContainer.style.opacity = 1;
2726
};
2827

2928
//////////////////////Shorter ES6 Syntax /////////////////////////////
29+
const handlErr = function (err) {
30+
countriesContainer.insertAdjacentText(
31+
'beforeend',
32+
`Something went wrong. ${err.message} Shitt Mannn 😲😲😲`
33+
);
34+
};
3035

3136
const getCountryInfo = function (country) {
3237
fetch(`https://restcountries.eu/rest/v2/name/${country}`)
@@ -40,7 +45,11 @@ const getCountryInfo = function (country) {
4045
.then(response => response.json())
4146
.then(data => {
4247
displayCountries(data, 'neighbour');
48+
})
49+
.catch(err => handlErr(err))
50+
.finally(() => {
51+
countriesContainer.style.opacity = 1;
4352
});
4453
};
4554

46-
btn.addEventListener('click', e => getCountryInfo('pakistan'));
55+
btn.addEventListener('click', e => getCountryInfo('paktan'));

0 commit comments

Comments
 (0)