Fix crash from messages with invalid timestamps

This commit is contained in:
Christian Bundy 2019-09-25 11:47:41 -07:00
parent e39fffd1e2
commit 88b96a386d
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
1 changed files with 12 additions and 1 deletions

View File

@ -114,7 +114,18 @@ const transform = (ssb, messages, myFeedId) => Promise.all(messages.map(async (m
const avatarUrl = `/image/32/${encodeURIComponent(avatarId)}`
const ts = new Date(msg.value.timestamp)
lodash.set(msg, 'value.meta.timestamp.received.iso8601', ts.toISOString())
let isoTs
try {
isoTs = ts.toISOString()
} catch (e) {
// Just in case it's an invalid date. :(
debug(e)
const receivedTs = new Date(msg.timestamp)
isoTs = receivedTs.toISOString()
}
lodash.set(msg, 'value.meta.timestamp.received.iso8601', isoTs)
const ago = Date.now() - Number(ts)
lodash.set(msg, 'value.meta.timestamp.received.since', prettyMs(ago, { compact: true }))