Skip to content

Commit

Permalink
Merge pull request #79 from tidepool-org/krystophv/electron
Browse files Browse the repository at this point in the history
WIP: Update superagent in order to be able to bundle for Electron
  • Loading branch information
krystophv authored Jul 11, 2017
2 parents a717413 + 17251e1 commit d0c1707
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 8 deletions.
12 changes: 11 additions & 1 deletion confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ module.exports = function (common, deps) {
.put(common.makeAPIUrl('/confirm/accept/signup/'+signupId))
.end(function (err, res) {
if (err != null) {
// TODO: update version of lodash so we can use _.get
err.message = (err.response && err.response.body && err.response.body.reason) || '';
return cb(err);
}
if (res.status !== 200) {
Expand All @@ -77,6 +79,8 @@ module.exports = function (common, deps) {
.send({birthday: birthday, password: password})
.end(function (err, res) {
if (err != null) {
err.error = (err.response && err.response.body && err.response.body.error) || '';
err.message = (err.response && err.response.body && err.response.body.reason) || '';
return cb(err);
}
if (res.status !== 200) {
Expand All @@ -98,6 +102,7 @@ module.exports = function (common, deps) {
.post(common.makeAPIUrl('/confirm/resend/signup/' + email))
.end(function (err, res) {
if (err != null) {
err.message = (err.response && err.response.error) || '';
return cb(err);
}
if (res.status !== 200) {
Expand Down Expand Up @@ -154,7 +159,10 @@ module.exports = function (common, deps) {
.end(
function (err, res) {
if (err != null) {
return cb(err);
if(err.status === 404) {
return cb(null,[]);
}
return cb( (err.response && err.response.body) || [] );
}
if (res.status === 200) {
return cb(null,res.body);
Expand Down Expand Up @@ -253,6 +261,7 @@ module.exports = function (common, deps) {
.post(common.makeAPIUrl('/confirm/send/forgot/' + email))
.end(function (err, res) {
if (err != null) {
err.message = (err.response && err.response.error) || '';
return cb(err);
}
if (res.status !== 200) {
Expand Down Expand Up @@ -280,6 +289,7 @@ module.exports = function (common, deps) {
.send(payload)
.end(function (err, res) {
if (err != null) {
err.message = (err.response && err.response.error) || '';
return cb(err);
}
if (res.status !== 200) {
Expand Down
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ module.exports = function (config, deps) {
.end(
function (err, res) {
if (err != null) {
if (err.status !== 201) {
return cb(new Error('Unexpected HTTP response: ' + err.status));
}
return cb(err);
} else if (res.error === true) {
if(_.isObject(res.body)) {
Expand Down Expand Up @@ -513,6 +516,9 @@ module.exports = function (config, deps) {
function (err, res) {

if (err != null) {
if (err.status !== 200) {
return cb((err.response && err.response.body) || err);
}
return cb(err);
} else if (res.status !== 200) {
return cb(res.body);
Expand Down Expand Up @@ -544,6 +550,9 @@ module.exports = function (config, deps) {
function (err, res) {

if (err != null) {
if (err.status !== 200) {
return cb((err.response && err.response.body) || err);
}
return cb(err);
} else if (res.status !== 200) {
return cb(res.body);
Expand Down Expand Up @@ -576,6 +585,9 @@ module.exports = function (config, deps) {
function (err, res) {

if (err != null) {
if (err.status !== 200) {
return cb((err.response && err.response.body) || err);
}
return cb(err);
} else if (res.status !== 200) {
return cb(res.body);
Expand Down Expand Up @@ -662,6 +674,7 @@ module.exports = function (config, deps) {
.end(
function (err, res) {
if (!_.isEmpty(err)) {
err.body = (err.response && err.response.body) || '';
log.info('Sync failed', JSON.stringify(err));
return done(err);
}
Expand Down Expand Up @@ -696,6 +709,7 @@ module.exports = function (config, deps) {
.end(
function (err, res) {
if (!_.isEmpty(err)) {
err.body = (err.response && err.response.body) || '';
log.info('Upload Failed');
return cb(err);
}
Expand Down Expand Up @@ -740,6 +754,7 @@ module.exports = function (config, deps) {
.end(
function (err, res) {
if (err) {
err.body = (err.response && err.response.body) || '';
return cb(err);
}

Expand Down
29 changes: 28 additions & 1 deletion lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = function (cfg, deps) {
return null;
}
// We previously exposed the user's session id here - which we identified as a security risk.
// We would have just removed the token query param altogether, but the URl that we direct user's to
// We would have just removed the token query param altogether, but the URl that we direct user's to
// is configured in a way where the token needs to be set for the Chrome Uploader to be launched
// So for now we are setting the token to a constant.
return makeUploadUrl('', { launchUploader: 'true' });
Expand Down Expand Up @@ -213,6 +213,15 @@ module.exports = function (cfg, deps) {
.end(
function (err, res) {
if (err != null) {
if (_.has(codes, err.status)) {
var handler = codes[err.status];
if (typeof(handler) === 'function') {
return cb(null, handler(err.response));
} else {
return cb(null, handler);
}
}
err.body = err.response.body;
return cb(err);
}

Expand Down Expand Up @@ -257,6 +266,15 @@ module.exports = function (cfg, deps) {
.end(
function (err, res) {
if (err != null) {
if (_.has(codes, err.status)) {
var handler = codes[err.status];
if (typeof(handler) === 'function') {
return cb(null, handler(err.response));
} else {
return cb(null, handler);
}
}
err.body = err.response.body;
return cb(err);
}

Expand Down Expand Up @@ -301,6 +319,15 @@ module.exports = function (cfg, deps) {
.end(
function (err, res) {
if (err != null) {
if (_.has(codes, err.status)) {
var handler = codes[err.status];
if (typeof(handler) === 'function') {
return cb(null, handler(err.response));
} else {
return cb(null, handler);
}
}
err.body = err.response.body;
return cb(err);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tidepool-platform-client",
"version": "0.31.1",
"version": "0.32.0",
"description": "Client-side library to interact with the Tidepool platform",
"main": "tidepool.js",
"scripts": {
Expand All @@ -14,7 +14,7 @@
"crypto": "0.0.3",
"lodash": "3.3.1",
"node-uuid": "1.4.3",
"superagent": "0.21.0"
"superagent": "1.2.0"
},
"devDependencies": {
"grunt": "0.4.5",
Expand Down
8 changes: 4 additions & 4 deletions test/integration/tidepoolPlatform_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('platform client', function () {
it('get another users public profile', function (done) {
//logged in as a_PWD you can get the profile for a_Member
pwdClient.findProfile(a_Member.id, function (error, profile) {
expect(error).to.deep.equal({ status: 401, body: 'Unauthorized' });
expect(error).to.include({ status: 401, body: 'Unauthorized' });
done();
});
});
Expand Down Expand Up @@ -279,7 +279,7 @@ describe('platform client', function () {
it('get another user\'s public preferences', function (done) {
//logged in as a_PWD you can get the profile for a_Member
pwdClient.findPreferences(a_Member.id, function (error, settings) {
expect(error).to.deep.equal({ status: 401, body: 'Unauthorized' });
expect(error).to.include({ status: 401, body: 'Unauthorized' });
done();
});
});
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('platform client', function () {
it('get another user\'s public settings', function (done) {
//logged in as a_PWD you can get the profile for a_Member
pwdClient.findSettings(a_Member.id, function (error, settings) {
expect(error).to.deep.equal({ status: 401, body: 'Unauthorized' });
expect(error).to.include({ status: 401, body: 'Unauthorized' });
done();
});
});
Expand Down Expand Up @@ -545,7 +545,7 @@ describe('platform client', function () {

it('but a_Member cannot see the other team members for a_PWD', function (done) {
memberClient.getTeamMembers(a_PWD.id, function (error, patientsTeam) {
expect(error).to.deep.equal({ status: 401, body: 'Unauthorized' });
expect(error).to.include({ status: 401, body: 'Unauthorized' });
done();
});
});
Expand Down
10 changes: 10 additions & 0 deletions user.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = function (common, config, deps) {
.end(
function (err, res) {
if (err) {
err.body = (err.response && err.response.body) || '';
return cb(err, null);
}
if (res.status !== 200) {
Expand Down Expand Up @@ -190,6 +191,7 @@ module.exports = function (common, config, deps) {
function (err, res) {

if (err != null) {
err.body = (err.response && err.response.body) || '';
return cb(err, null);
}

Expand Down Expand Up @@ -232,6 +234,7 @@ module.exports = function (common, config, deps) {
.end(
function (err, res) {
if (err != null) {
err.body = (err.response && err.response.body) || '';
return cb(err, null);
}

Expand Down Expand Up @@ -300,6 +303,7 @@ module.exports = function (common, config, deps) {
.end(
function (err, res) {
if (err != null) {
err.body = (err.response && err.response.body) || '';
return cb(err);
}
var theUserId = res.body.userid;
Expand Down Expand Up @@ -337,6 +341,8 @@ module.exports = function (common, config, deps) {
.end(
function (err, res) {
if (err != null) {
err.body = (err.response && err.response.body) || '';
err.message = (err.response && err.response.error) || '';
return next(err);
}
if(res.status === 201){
Expand All @@ -355,6 +361,8 @@ module.exports = function (common, config, deps) {
.end(
function (err, res) {
if (err != null) {
err.body = (err.response && err.response.body) || '';
err.message = (err.response && err.response.error) || '';
return next(err);
}
if(res.status === 200){
Expand All @@ -375,6 +383,8 @@ module.exports = function (common, config, deps) {
.end(
function (err, res) {
if (err != null) {
err.body = (err.response && err.response.body) || '';
err.message = (err.response && err.response.error) || '';
return next(err);
}
if(res.status === 200){
Expand Down

0 comments on commit d0c1707

Please sign in to comment.