0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

upstream error handling

This commit is contained in:
Alex Kocharin 2013-06-14 11:56:02 +04:00
parent e92e582b88
commit f0f1f76286
3 changed files with 20 additions and 8 deletions

View file

@ -109,16 +109,25 @@ module.exports = function(config_hash) {
if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route'); if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route');
res.status(200); res.status(200);
return res.send({ return res.send({
ok: 'hello there' ok: 'you are authenticated as "' + req.user + '"',
}); });
}); });
app.put('/-/user/:argument', function(req, res, next) { 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 // can't put 'org.couchdb.user' in route address for some reason
if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route'); if (req.params.argument.split(':')[0] !== 'org.couchdb.user') return next('route');
res.status(201); res.status(201);
return res.send({ return res.send({
ok: 'we don\'t accept new users, but pretend that we do...', ok: 'you are authenticated as "' + req.user + '"',
}); });
}); });

View file

@ -23,6 +23,9 @@ Storage.prototype.get_package = function(name, callback) {
ca: this.ca, ca: this.ca,
}, function(err, res, body) { }, function(err, res, body) {
if (err) return callback(err); if (err) return callback(err);
if (!(res.statusCode >= 200 && res.statusCode < 300)) {
return callback(new Error('bad status code: ' + res.statusCode));
}
callback(null, body); callback(null, body);
}); });
} }

View file

@ -53,18 +53,18 @@ Storage.prototype.get_package = function(name, callback) {
up.get_package(name, function(err, up_res) { up.get_package(name, function(err, up_res) {
if (err) return cb(); 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 { try {
utils.validate_metadata(up_res, name); utils.validate_metadata(up_res, name);
} catch(err) { } catch(err) {
return cb(); 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) { ['versions', 'dist-tags'].forEach(function(key) {
for (var i in up_res[key]) { for (var i in up_res[key]) {
if (!result[key][i] || is_latest) { if (!result[key][i] || is_latest) {