From 67a25c9ddd212b0ac4ebf91bd953d41f8a750337 Mon Sep 17 00:00:00 2001 From: Eric Tschetter Date: Mon, 31 Aug 2015 21:09:05 -0700 Subject: [PATCH] Compatibility Fixes While trying to setup some integrated performance tests, I ran into issues with platform-client calls not actually working (or doing what I expected). These are some fixes that allow the client to operate. All changes should be additions, i.e. old behavior shouldn't change. --- index.js | 14 +++++++++++--- tidepool.js | 4 ++++ user.js | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 19d6ec6..9bd774e 100644 --- a/index.js +++ b/index.js @@ -35,8 +35,8 @@ module.exports = function (config, deps) { var superagent = requireDep(deps, 'superagent'); var log = requireDep(deps, 'log'); + var config = _.clone(config); - config = _.clone(config); requireConfig(config, 'host'); requireConfig(config, 'metricsSource'); requireConfig(config, 'metricsVersion'); @@ -481,9 +481,13 @@ module.exports = function (config, deps) { var syncTask = res.body; var syncTaskId = syncTask.id; - if (!syncTaskId) { + if (syncTaskId == null) { + syncTaskId = res.body.syncTaskId; + } + + if (syncTaskId == null) { log.info('Upload Failed'); - return cb({message: 'No sync task id'}); + return cb({message: 'No sync task id', response: res.body}); } waitForSyncTaskWithIdToFinish(syncTaskId,function(err,data){ @@ -520,6 +524,10 @@ module.exports = function (config, deps) { return common.handleHttpError(res, cb); } + if (res.headers['content-type'] === 'application/octet-stream') { + return superagent.parse.text(res, function(){ cb(null, res.text); }); + } + return cb(null, res.text); }); }, diff --git a/tidepool.js b/tidepool.js index 9aa15b0..f414657 100644 --- a/tidepool.js +++ b/tidepool.js @@ -18,6 +18,7 @@ var superagent = require('superagent'); var _ = require('lodash'); +var inMemStore = require('./lib/inMemoryStorage'); var makeClient = require('./index'); // Public-facing API, used by app developers @@ -48,6 +49,9 @@ module.exports = function(options) { removeItem: function() {} }; } + if (localStore === 'memory') { + localStore = inMemStore(); + } return makeClient(_.omit(options, 'log', 'superagent', 'localStore'), { log: log, diff --git a/user.js b/user.js index b6bee84..d07490e 100644 --- a/user.js +++ b/user.js @@ -303,6 +303,10 @@ module.exports = function (common, config, deps) { if (err != null) { return cb(err); } + if (res.error) { + return cb(res.error) + } + var theUserId = res.body.userid; var theToken = res.headers[common.SESSION_TOKEN_HEADER];