Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

wrap JSON.parse calls in try-catch blocks #39

Merged
merged 1 commit into from
Dec 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ Plotly.prototype.plot = function(data, graphOptions, callback) {

var req = https.request(options, function (res) {
parseRes(res, function (err, body) {
body = JSON.parse(body);

/* Try to parse the response */
try {
body = JSON.parse(body);
} catch (e) {
callback(e);
}

if ( body['stream-status'] != undefined) {
self.streamHost = url.parse(body['stream-host']).hostname;
Expand Down Expand Up @@ -169,13 +175,23 @@ Plotly.prototype.getFigure = function (fileOwner, fileId, callback) {

var req = https.get(options, function (res) {
parseRes(res, function (err, body) {
if (JSON.parse(body).error) {
err = JSON.parse(body).error;
callback(err);
} else {
var figure = JSON.parse(body).payload.figure;

/* Try to parse the response */
try {
body = JSON.parse(body);
} catch (e) {
callback(e);
}

if (body.error) {
callback(body.error);
}

else {
var figure = body.payload.figure;
callback(null, figure);
}

});
});

Expand Down