Skip to content

Commit 0914c83

Browse files
committed
get-webhook-event-payload: be more careful about missing epochs
When we run out of payloads to iterate on, we may well operate on `null` objects when trying to access the `epoch` attribute. Let's be more careful about that. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 52e3fe4 commit 0914c83

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

get-webhook-event-payload.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@
8080
if (answer.oldest.epoch > until) {
8181
let tooNew = answer.oldest
8282
// first find a good starting cursor
83-
while (answer.oldest.epoch > until) {
83+
while (answer.oldest?.epoch && answer.oldest.epoch > until) {
8484
tooNew = answer.oldest
8585

8686
const rate = (answer.newest.id - answer.oldest.id) / (answer.newest.epoch - answer.oldest.epoch)
8787
let cursor = Math.floor(answer.oldest.id - rate * (answer.oldest.epoch - until))
8888
answer = await getAtCursor(cursor)
8989
}
9090

91-
while (answer.newest.epoch < until) {
91+
while (answer.newest?.epoch && answer.newest.epoch < until) {
9292
const tooOldID = answer.newest.id
9393
// we overshot, now the time window does not include `until`, backtrack via bisecting
9494
const rate = (tooNew.id - answer.newest.id) / (tooNew.epoch - answer.newest.epoch)
@@ -101,14 +101,14 @@
101101
}
102102
}
103103

104-
while (answer.oldest.epoch > until) {
104+
while (answer.oldest?.epoch && answer.oldest.epoch > until) {
105105
// we overshot, maybe again, now even the oldest is too new
106106
answer = await getAtCursor(answer.oldest.id - 1)
107107
}
108108
}
109109

110110
const events = [...answer.events]
111-
while (answer.oldest.epoch > since) {
111+
while (answer.oldest?.epoch && answer.oldest.epoch > since) {
112112
answer = await getAtCursor(answer.oldest.id - 1)
113113
events.push(...answer.events)
114114
}

0 commit comments

Comments
 (0)