File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed
Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,10 @@ const fetchRadar = (dt, opts) =>
9191 if ( e . statusCode == 404 ) {
9292 reject ( new Error ( 'Page not found' ) ) ;
9393 } else {
94- console . error ( e ) ;
94+ console . error ( {
95+ message : e . message ,
96+ code : e . code ,
97+ } ) ;
9598 reject ( e ) ;
9699 }
97100 } ) ;
@@ -221,6 +224,7 @@ const convertImageToData = (img) => {
221224
222225const cachedOutput = { } ;
223226module . exports = async ( req , res ) => {
227+ console . log ( '❇️ START' ) ;
224228 console . time ( 'RESPONSE' ) ;
225229 try {
226230 let dt , output ;
@@ -248,12 +252,16 @@ module.exports = async (req, res) => {
248252 try {
249253 img = await fetchRadar ( dt ) ;
250254 } catch ( e ) {
251- // Retry with older radar image
252- dt = datetimeStr ( - 5 ) ;
253- output = cachedOutput [ dt ] ;
254-
255- if ( ! output ) {
256- img = await fetchRadar ( dt ) ;
255+ for ( let i = 1 ; i <= 5 ; i ++ ) {
256+ // Step back 5 minutes every time
257+ dt = datetimeStr ( i * - 5 ) ;
258+ console . log ( 'Retry with older image' , dt ) ;
259+ output = cachedOutput [ dt ] ;
260+ if ( output ) break ;
261+ try {
262+ img = await fetchRadar ( dt , { retry : 0 } ) ;
263+ break ;
264+ } catch ( e ) { }
257265 }
258266 }
259267 if ( ! output ) {
You can’t perform that action at this time.
0 commit comments