File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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
3136const 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 ' ) ) ;
You can’t perform that action at this time.
0 commit comments