@@ -49,7 +49,7 @@ api.get('/', (req, res) => {
4949 }
5050
5151 return weather ( coords . lat , coords . lon , coords . timezone )
52- } ) . catch ( ( coords ) => {
52+ } ) . catch ( ( ) => {
5353 // If the geolocation fails, default to Toronto, Ontario, Canada, then call
5454 // the weather API with the coordinates and timezone.
5555
@@ -62,13 +62,28 @@ api.get('/', (req, res) => {
6262 // template values specified in `renderValues`.
6363
6464 renderValues . forecast = weatherData
65- res . render ( 'index' , renderValues )
65+ return res . render ( 'index' , renderValues , function ( err , html ) {
66+ if ( err ) {
67+ console . error ( "Error rendering index page:" , err )
68+ return res . status ( 500 ) . send ( 'An error occurred while rendering the page.' )
69+ } else {
70+ return res . send ( html )
71+ }
72+ } )
6673 } ) . catch ( ( e ) => {
6774 // If the weather API call fails, render the index page with the template
6875 // and the limited values that are available.
6976
7077 console . error ( "Error in main route:" , e )
71- res . render ( 'index' , renderValues )
78+ res . render ( 'index' , renderValues , function ( err , html ) {
79+ if ( err ) {
80+ console . error ( "Error rendering index page:" , err )
81+ return res . status ( 500 ) . send ( 'An error occurred while rendering the page.' )
82+ } else {
83+ return res . send ( html )
84+ }
85+
86+ } )
7287 } )
7388} )
7489
0 commit comments