From b25eddbf5ec0b73af9f8cc3a93970dac2d7a4559 Mon Sep 17 00:00:00 2001 From: LJNeon <23249107+LJNeon@users.noreply.github.com> Date: Thu, 24 Jun 2021 17:26:02 -0700 Subject: [PATCH] Standardized parsing error --- lib/gateway/Shard.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index df4710d5c..1f99e8dec 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -2175,11 +2175,19 @@ class Shard extends EventEmitter { } data = Buffer.from(this._zlibSync.result); - if(Erlpack) { - return this.onPacket(Erlpack.unpack(data)); - } else { - return this.onPacket(JSON.parse(data.toString())); + + try { + if(Erlpack) { + data = Erlpack.unpack(data); + } else { + data = JSON.parse(data.toString()); + } + } catch(err) { + this.emit("error", Error(`parsing error: ${err.message}`)); + return; } + + return this.onPacket(data); } else { this._zlibSync.push(data, false); }