0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-27 22:59:51 -05:00

"msg" -> "message"

former one created too much confusion
This commit is contained in:
Alex Kocharin 2014-07-22 23:31:01 +04:00
parent 48b7031074
commit 9275b2cc85
6 changed files with 56 additions and 56 deletions

View file

@ -1,24 +1,24 @@
var util = require('util')
, utils = require('./utils')
function parse_error_params(params, status, msg) {
function parse_error_params(params, status, message) {
if (typeof(params) === 'string') {
return {
msg: params,
message: params,
status: status,
}
} else if (typeof(params) === 'number') {
return {
msg: msg,
message: message,
status: params,
}
} else if (utils.is_object(params)) {
if (params.msg == null) params.msg = msg
if (params.message == null) params.message = message
if (params.status == null) params.status = status
return params
} else {
return {
msg: msg,
message: message,
status: status,
}
}
@ -30,7 +30,7 @@ function parse_error_params(params, status, msg) {
var AppError = function(params, constr) {
Error.captureStackTrace(this, constr || this)
params = parse_error_params(params, 500, 'Internal server error')
this.msg = params.msg
this.message = params.message
this.status = params.status
}
util.inherits(AppError, Error)
@ -41,7 +41,7 @@ AppError.prototype.name = 'Application Error'
*/
var UserError = function(params, constr) {
params = parse_error_params(params, 404, 'The requested resource was not found')
this.msg = params.msg
this.message = params.message
this.status = params.status
}
util.inherits(UserError, Error)

View file

@ -33,18 +33,18 @@ module.exports = function(config_hash) {
} else {
if (!req.remoteUser) {
if (req.remoteUserError) {
var msg = "can't "+action+' restricted package, ' + req.remoteUserError
var message = "can't "+action+' restricted package, ' + req.remoteUserError
} else {
var msg = "can't "+action+" restricted package without auth, did you forget 'npm set always-auth true'?"
var message = "can't "+action+" restricted package without auth, did you forget 'npm set always-auth true'?"
}
next(new UError({
status: 403,
msg: msg,
message: message,
}))
} else {
next(new UError({
status: 403,
msg: 'user '+req.remoteUser+' not allowed to '+action+' it'
message: 'user '+req.remoteUser+' not allowed to '+action+' it'
}))
}
}
@ -64,7 +64,7 @@ module.exports = function(config_hash) {
if (err.status && err.status >= 400 && err.status < 600) {
if (calls == 1) {
res.status(err.status)
res.send({error: err.msg || err.message || 'unknown error'})
res.send({error: err.message || 'unknown error'})
}
} else {
Logger.logger.error({err: err}, 'unexpected error: @{!err.message}\n@{err.stack}')
@ -154,7 +154,7 @@ module.exports = function(config_hash) {
return next(new UError({
status: 404,
msg: 'version not found: ' + req.params.version
message: 'version not found: ' + req.params.version
}))
})
})
@ -266,7 +266,7 @@ module.exports = function(config_hash) {
return next(new UError({
// 501 status is more meaningful, but npm doesn't show error message for 5xx
status: 404,
msg: 'npm star|unstar calls are not implemented',
message: 'npm star|unstar calls are not implemented',
}))
}
@ -275,7 +275,7 @@ module.exports = function(config_hash) {
} catch(err) {
return next(new UError({
status: 422,
msg: 'bad incoming package data',
message: 'bad incoming package data',
}))
}
@ -312,7 +312,7 @@ module.exports = function(config_hash) {
// if this happens in normal circumstances, report it as a bug
return next(new UError({
status: 400,
msg: 'unsupported registry call',
message: 'unsupported registry call',
}))
}

View file

@ -35,13 +35,13 @@ function get_boilerplate(name) {
}
}
Storage.prototype._internal_error = function(err, file, msg) {
Storage.prototype._internal_error = function(err, file, message) {
this.logger.error( {err: err, file: file}
, msg + ' @{file}: @{!err.message}'
, message + ' @{file}: @{!err.message}'
)
return new UError({
status: 500,
msg: 'internal server error'
message: 'internal server error'
})
}
@ -50,7 +50,7 @@ Storage.prototype.add_package = function(name, metadata, callback) {
if (err && err.code === 'EEXISTS') {
return callback(new UError({
status: 409,
msg: 'this package is already present'
message: 'this package is already present'
}))
}
callback()
@ -65,7 +65,7 @@ Storage.prototype.remove_package = function(name, callback) {
if (err.code === 'ENOENT') {
return callback(new UError({
status: 404,
msg: 'no such package available',
message: 'no such package available',
}))
} else {
return callback(err)
@ -195,7 +195,7 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
if (data.versions[version] != null) {
return cb(new UError({
status: 409,
msg: 'this version already present'
message: 'this version already present'
}))
}
@ -207,7 +207,7 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
if (data._attachments[tarball].shasum != metadata.dist.shasum) {
return cb(new UError({
status: 400,
msg: 'shasum error, ' + data._attachments[tarball].shasum + ' != ' + metadata.dist.shasum,
message: 'shasum error, ' + data._attachments[tarball].shasum + ' != ' + metadata.dist.shasum,
}))
}
}
@ -230,7 +230,7 @@ Storage.prototype.add_tags = function(name, tags, callback) {
if (data.versions[tags[t]] == null) {
return cb(new UError({
status: 404,
msg: "this version doesn't exist"
message: "this version doesn't exist"
}))
}
@ -252,7 +252,7 @@ Storage.prototype.change_package = function(name, metadata, revision, callback)
if (!utils.is_object(metadata.versions) || !utils.is_object(metadata['dist-tags'])) {
return callback(new UError({
status: 422,
msg: 'bad data',
message: 'bad data',
}))
}
@ -288,7 +288,7 @@ Storage.prototype.remove_tarball = function(name, filename, revision, callback)
} else {
cb(new UError({
status: 404,
msg: 'no such file available',
message: 'no such file available',
}))
}
}, function(err) {
@ -315,7 +315,7 @@ Storage.prototype.add_tarball = function(name, filename) {
if (name === info_file || name === '__proto__') {
stream.emit('error', new UError({
status: 403,
msg: 'can\'t use this filename'
message: 'can\'t use this filename'
}))
}
@ -325,7 +325,7 @@ Storage.prototype.add_tarball = function(name, filename) {
if (err.code === 'EEXISTS') {
stream.emit('error', new UError({
status: 409,
msg: 'this tarball is already present'
message: 'this tarball is already present'
}))
} else if (err.code === 'ENOENT') {
// check if package exists to throw an appropriate message
@ -366,7 +366,7 @@ Storage.prototype.add_tarball = function(name, filename) {
if (!length) {
stream.emit('error', new UError({
status: 422,
msg: 'refusing to accept zero-length file'
message: 'refusing to accept zero-length file'
}))
wstream.abort()
} else {
@ -391,7 +391,7 @@ Storage.prototype.get_tarball = function(name, filename, callback) {
if (err && err.code === 'ENOENT') {
stream.emit('error', new UError({
status: 404,
msg: 'no such file available',
message: 'no such file available',
}))
} else {
stream.emit('error', err)
@ -418,7 +418,7 @@ Storage.prototype.get_package = function(name, options, callback) {
if (err.code === 'ENOENT') {
return callback(new UError({
status: 404,
msg: 'no such package available'
message: 'no such package available'
}))
} else {
return callback(self._internal_error(err, info_file, 'error reading'))
@ -491,12 +491,12 @@ Storage.prototype.update_package = function(name, updateFn, _callback) {
if (err.code === 'EAGAIN') {
return callback(new UError({
status: 503,
msg: 'resource temporarily unavailable'
message: 'resource temporarily unavailable'
}))
} else if (err.code === 'ENOENT') {
return callback(new UError({
status: 404,
msg: 'no such package available',
message: 'no such package available',
}))
} else {
return callback(err)

View file

@ -12,7 +12,7 @@ module.exports.validate_name = function validate_name(req, res, next, value, nam
} else {
next(new UError({
status: 403,
msg: 'invalid ' + name,
message: 'invalid ' + name,
}))
}
}
@ -22,7 +22,7 @@ module.exports.media = function media(expect) {
if (req.headers['content-type'] !== expect) {
next(new UError({
status: 415,
msg: 'wrong content-type, expect: '+expect+', got: '+req.headers['content-type'],
message: 'wrong content-type, expect: '+expect+', got: '+req.headers['content-type'],
}))
} else {
next()
@ -34,7 +34,7 @@ module.exports.expect_json = function expect_json(req, res, next) {
if (!utils.is_object(req.body)) {
return next({
status: 400,
msg: 'can\'t parse incoming json',
message: 'can\'t parse incoming json',
})
}
next()
@ -50,7 +50,7 @@ module.exports.basic_auth = function basic_auth(callback) {
// swallow error, user remains unauthorized
// set remoteUserError to indicate that user was attempting authentication
if (err) req.remoteUserError = err.msg
if (err) req.remoteUserError = err.message
return _next()
}
@ -63,7 +63,7 @@ module.exports.basic_auth = function basic_auth(callback) {
if (parts.length !== 2) return next({
status: 400,
msg: 'bad authorization header',
message: 'bad authorization header',
})
var scheme = parts[0]
@ -72,7 +72,7 @@ module.exports.basic_auth = function basic_auth(callback) {
if (scheme !== 'Basic' || index < 0) return next({
status: 400,
msg: 'bad authorization header',
message: 'bad authorization header',
})
var user = credentials.slice(0, index)
@ -86,7 +86,7 @@ module.exports.basic_auth = function basic_auth(callback) {
} else {
next({
status: 403,
msg: 'bad username/password, access denied',
message: 'bad username/password, access denied',
})
}
})
@ -102,7 +102,7 @@ module.exports.anti_loop = function(config) {
if (m && m[2] === config.server_id) {
return next(new UError({
status: 508,
msg: 'loop detected',
message: 'loop detected',
}))
}
}
@ -176,11 +176,11 @@ module.exports.log_and_etagify = function(req, res, next) {
}
function log() {
var msg = '@{status}, user: @{user}, req: \'@{request.method} @{request.url}\''
var message = '@{status}, user: @{user}, req: \'@{request.method} @{request.url}\''
if (res._sinopia_error) {
msg += ', error: @{!error}'
message += ', error: @{!error}'
} else {
msg += ', bytes: @{bytes.in}/@{bytes.out}'
message += ', bytes: @{bytes.in}/@{bytes.out}'
}
req.log.warn({
request: {method: req.method, url: req.url},
@ -192,7 +192,7 @@ module.exports.log_and_etagify = function(req, res, next) {
in: bytesin,
out: bytesout,
}
}, msg)
}, message)
}
req.on('close', function() {

View file

@ -65,7 +65,7 @@ Storage.prototype.add_package = function(name, metadata, callback) {
if (results) {
return cb(new UError({
status: 409,
msg: 'this package is already present'
message: 'this package is already present'
}))
}
@ -82,7 +82,7 @@ Storage.prototype.add_package = function(name, metadata, callback) {
if (results) {
return cb(new UError({
status: 409,
msg: 'this package is already present'
message: 'this package is already present'
}))
}
@ -93,7 +93,7 @@ Storage.prototype.add_package = function(name, metadata, callback) {
if (err_results[i][0].status !== 404) {
return cb(new UError({
status: 503,
msg: 'one of the uplinks is down, refuse to publish'
message: 'one of the uplinks is down, refuse to publish'
}))
}
}
@ -485,7 +485,7 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,
if (!exists) {
return callback(new UError({
status: 404,
msg: 'no such package available'
message: 'no such package available'
}), null, uplink_errors)
}

View file

@ -181,11 +181,11 @@ Storage.prototype.request = function(options, cb) {
}
function do_log() {
var msg = '@{!status}, req: \'@{request.method} @{request.url}\''
var message = '@{!status}, req: \'@{request.method} @{request.url}\''
if (error) {
msg += ', error: @{!error}'
message += ', error: @{!error}'
} else {
msg += ', bytes: @{bytes.in}/@{bytes.out}'
message += ', bytes: @{bytes.in}/@{bytes.out}'
}
self.logger.warn({
err: err,
@ -197,7 +197,7 @@ Storage.prototype.request = function(options, cb) {
in: json ? json.length : 0,
out: res_length || 0,
}
}, msg)
}, message)
}
})
@ -266,7 +266,7 @@ Storage.prototype.get_package = function(name, options, callback) {
if (err) return callback(err)
if (res.statusCode === 404) {
return callback(new UError({
msg: 'package doesn\'t exist on uplink',
message: 'package doesn\'t exist on uplink',
status: 404,
}))
}
@ -300,13 +300,13 @@ Storage.prototype.get_url = function(url) {
rstream.on('response', function(res) {
if (res.statusCode === 404) {
return stream.emit('error', new UError({
msg: 'file doesn\'t exist on uplink',
message: 'file doesn\'t exist on uplink',
status: 404,
}))
}
if (!(res.statusCode >= 200 && res.statusCode < 300)) {
return stream.emit('error', new UError({
msg: 'bad uplink status code: ' + res.statusCode,
message: 'bad uplink status code: ' + res.statusCode,
status: 500,
}))
}