From f0f1f76286603ea94dca52bc4cd8f62e4e8ea16f Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 14 Jun 2013 11:56:02 +0400 Subject: [PATCH] upstream error handling --- lib/index.js | 13 +++++++++++-- lib/st-proxy.js | 3 +++ lib/storage.js | 12 ++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 507818cb1..73f3e824a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -109,16 +109,25 @@ module.exports = function(config_hash) { if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route'); res.status(200); return res.send({ - ok: 'hello there' + ok: 'you are authenticated as "' + req.user + '"', }); }); app.put('/-/user/:argument', function(req, res, next) { + // can't put 'org.couchdb.user' in route address for some reason + if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route'); + res.status(409); + return res.send({ + error: 'registration is not implemented', + }); + }); + + app.put('/-/user/:argument/-rev/*', function(req, res, next) { // can't put 'org.couchdb.user' in route address for some reason if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route'); res.status(201); return res.send({ - ok: 'we don\'t accept new users, but pretend that we do...', + ok: 'you are authenticated as "' + req.user + '"', }); }); diff --git a/lib/st-proxy.js b/lib/st-proxy.js index f5442934b..6515de8d0 100644 --- a/lib/st-proxy.js +++ b/lib/st-proxy.js @@ -23,6 +23,9 @@ Storage.prototype.get_package = function(name, callback) { ca: this.ca, }, function(err, res, body) { if (err) return callback(err); + if (!(res.statusCode >= 200 && res.statusCode < 300)) { + return callback(new Error('bad status code: ' + res.statusCode)); + } callback(null, body); }); } diff --git a/lib/storage.js b/lib/storage.js index ed9a9134b..addac36d4 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -53,18 +53,18 @@ Storage.prototype.get_package = function(name, callback) { up.get_package(name, function(err, up_res) { if (err) return cb(); - var this_version = up_res['dist-tags'].latest; - if (!semver.gt(latest, this_version) && this_version) { - latest = this_version; - var is_latest = true; - } - try { utils.validate_metadata(up_res, name); } catch(err) { return cb(); } + var this_version = up_res['dist-tags'].latest; + if (!semver.gt(latest, this_version) && this_version) { + latest = this_version; + var is_latest = true; + } + ['versions', 'dist-tags'].forEach(function(key) { for (var i in up_res[key]) { if (!result[key][i] || is_latest) {