Skip to content

Commit ba4d59b

Browse files
committed
Add multiple step backs
Also clean up the dev logs
1 parent ebdb91e commit ba4d59b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

api/rainarea.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff 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

222225
const cachedOutput = {};
223226
module.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) {

0 commit comments

Comments
 (0)