From 77aefd686fd362a3a98124f2b0c9759445ab3088 Mon Sep 17 00:00:00 2001 From: Christian Holm Date: Thu, 5 May 2016 19:55:35 +0200 Subject: [PATCH] Reveal any data supplied, even if not JSON --- lib/mixpanel-node.js | 2 +- test/send_request.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/mixpanel-node.js b/lib/mixpanel-node.js index fa1ddfc..4d79b5c 100644 --- a/lib/mixpanel-node.js +++ b/lib/mixpanel-node.js @@ -83,7 +83,7 @@ var create_client = function(token, config) { } } catch(ex) { - e = new Error("Could not parse response from Mixpanel"); + e = new Error("Could not parse response from Mixpanel: " + JSON.stringify(data)); } } else { diff --git a/test/send_request.js b/test/send_request.js index ed003fd..fd996cd 100644 --- a/test/send_request.js +++ b/test/send_request.js @@ -59,6 +59,35 @@ exports.send_request = { this.res.emit('end'); }, + "handles mixpanel verbose errors": function(test) { + test.expect(1); + this.mixpanel.config.verbose = true; + this.mixpanel.send_request("/track", { event: "test" }, function(e) { + test.equal(e.message, 'Mixpanel Server Error: Foobar'); + test.done(); + }); + + this.res.emit('data', JSON.stringify({ + status: 0, + error: 'Foobar' + })); + this.res.emit('end'); + this.mixpanel.config.verbose = false; + }, + + "handles mixpanel verbose errors with non-verbose response": function(test) { + test.expect(1); + this.mixpanel.config.verbose = true; + this.mixpanel.send_request("/track", { event: "test" }, function(e) { + test.equal(e.message, 'Could not parse response from Mixpanel: ""'); + test.done(); + }); + + this.res.emit('data', ''); + this.res.emit('end'); + this.mixpanel.config.verbose = false; + }, + "handles http.get errors": function(test) { test.expect(1); this.mixpanel.send_request("/track", { event: "test" }, function(e) {