try catch

This commit is contained in:
boufni95 2025-01-29 15:25:05 +00:00
parent d11f83b05a
commit 3b2e376ffa

View file

@ -78,29 +78,33 @@ export default class webRTC {
console.log('ondatachannel', event) console.log('ondatachannel', event)
const channel = event.channel const channel = event.channel
channel.addEventListener('message', async (event) => { channel.addEventListener('message', async (event) => {
const j = JSON.parse(event.data) as Types.SingleUsageMetricReq try {
const err = Types.SingleUsageMetricReqValidate(j, { const j = JSON.parse(event.data) as Types.SingleUsageMetricReq
app_id_CustomCheck: id => id === u.appId, const err = Types.SingleUsageMetricReqValidate(j, {
metrics_name_CustomCheck: name => name !== "" app_id_CustomCheck: id => id === u.appId,
}) metrics_name_CustomCheck: name => name !== ""
if (err) { })
this.log(ERROR, 'SingleUsageMetricReqValidate', err) if (err) {
return this.log(ERROR, 'SingleUsageMetricReqValidate', err)
} return
const res = await this.storage.metricsEventStorage.LoadRawMetricsFile(j.app_id, j.metrics_name, j.page) }
const id = Math.floor(Math.random() * 2_000_000_000) const res = await this.storage.metricsEventStorage.LoadRawMetricsFile(j.app_id, j.metrics_name, j.page)
let i = 0 const id = Math.floor(Math.random() * 2_000_000_000)
const packets: Buffer[] = [] let i = 0
while (i < res.length) { const packets: Buffer[] = []
const chunk = res.slice(i, Math.min(i + 15_000, res.length)) while (i < res.length) {
packets.push(chunk) const chunk = res.slice(i, Math.min(i + 15_000, res.length))
i += 15_000 packets.push(chunk)
} i += 15_000
for (let i = 0; i < packets.length; i++) { }
const packet = packets[i] for (let i = 0; i < packets.length; i++) {
const tlv = encodeTLVDataPacket({ dataId: id, packetNum: i + 1, totalPackets: packets.length, data: packet }) const packet = packets[i]
const bytes = encodeTLV(tlv) const tlv = encodeTLVDataPacket({ dataId: id, packetNum: i + 1, totalPackets: packets.length, data: packet })
channel.send(bytes) const bytes = encodeTLV(tlv)
channel.send(bytes)
}
} catch (e: any) {
this.log(ERROR, 'ondatachannel', e.message || e)
} }
}) })
} }