diff --git a/lib/index.ts b/lib/index.ts index 7b62fbd..8a9f71c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -87,12 +87,7 @@ export class Encoder { // json data if (null != obj.data) { - const payload = tryStringify(obj.data); - if (payload !== false) { - str += payload; - } else { - return ERROR_PACKET; - } + str += JSON.stringify(obj.data); } debug("encoded %j as %s", obj, str); @@ -117,22 +112,11 @@ export class Encoder { } } -const ERROR_PACKET = PacketType.ERROR + '"encode error"'; - -function tryStringify(str) { - try { - return JSON.stringify(str); - } catch (e) { - return false; - } -} - /** * A socket.io Decoder instance * * @return {Object} decoder */ -// @ts-ignore export class Decoder extends Emitter { private reconstructor: BinaryReconstructor; diff --git a/test/parser.js b/test/parser.js index d63e08a..e2f05ea 100644 --- a/test/parser.js +++ b/test/parser.js @@ -59,7 +59,7 @@ describe('parser', function(){ }); }); - it('properly handles circular objects', function() { + it('throws an error when encoding circular objects', function() { var a = {}; a.b = a; @@ -72,9 +72,7 @@ describe('parser', function(){ const encoder = new Encoder(); - encoder.encode(data, function(encodedPackets) { - expect(encodedPackets[0]).to.be('4"encode error"'); - }); + expect(() => encoder.encode(data)).to.throwException(); }); it('decodes a bad binary packet', function(){