From 9dc4a2b2675d43e4bd87d9d54dcea170cb11a256 Mon Sep 17 00:00:00 2001 From: Alexandre Hauser Date: Mon, 15 Feb 2016 12:13:48 +0100 Subject: [PATCH 1/3] Added option for https --- lib/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index ec4a50a..c63b027 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,10 +2,11 @@ var assert = require('assert'); -var http = require('http'), - jayson = require('jayson'), +var jayson = require('jayson'), _ = require('lodash'); +var http; // set on connect depending on the option given by the user + var Odoo = function (config) { config = config || {}; @@ -14,6 +15,7 @@ var Odoo = function (config) { this.database = config.database; this.username = config.username; this.password = config.password; + this.protocol = config.protocol || "http" }; // Connect @@ -40,6 +42,8 @@ Odoo.prototype.connect = function (cb) { var self = this; + http = require(this.protocol) + var req = http.request(options, function (res) { var response = ''; @@ -203,7 +207,7 @@ Odoo.prototype._request = function (path, params, callback) { } }; - var client = jayson.client.http(options); + var client = jayson.client[this.protocol](options); client.request('call', params, function (e, err, res) { if (e || err) { From 282c6b0f24e1614b5c648d7a858f4597350efe6c Mon Sep 17 00:00:00 2001 From: lowi Date: Fri, 10 Nov 2017 08:57:55 +0100 Subject: [PATCH 2/3] Wrap json.parse in try {} catch() --- lib/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index c63b027..ee82fe2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -54,7 +54,12 @@ Odoo.prototype.connect = function (cb) { }); res.on('end', function () { - response = JSON.parse(response); + try { + response = JSON.parse(response); + } + catch(err) { + return cb(err, null); + } if (response.error) { return cb(response.error, null); From 994c35cbb60cf4108ed6bbc8656746ca30ee943d Mon Sep 17 00:00:00 2001 From: lowi Date: Fri, 10 Nov 2017 09:06:52 +0100 Subject: [PATCH 3/3] Update version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e79f8b3..ff92574 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "odoo", - "version": "0.4.0", + "version": "0.4.2", "description": "Node.js client library for Odoo using JSON-RPC", "main": "./lib/index.js", "directories": {