refactor: nicer errors

This commit is contained in:
cha0s 2021-01-21 19:27:15 -06:00
parent 580440f42d
commit 5724d69488

View File

@ -8,6 +8,19 @@ export default (latus) => class BundlePacket extends PacketClass {
return 'buffer';
}
static encode(packets) {
try {
return this.builder.encode(this.pack(packets));
}
catch (error) {
const packetTypes = packets
.map((packet) => normalize(latus, packet))
.map(({constructor: {type}}) => type);
error.message = `${this.type}(${packetTypes.join(', ')}): ${error.message}`;
throw error;
}
}
static pack(packets) {
// Pack up all the packets.
const packedPackets = new Array(packets.length);