mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
logging fs errors
This commit is contained in:
parent
012892600b
commit
3ca3ac2dae
26
lib/index.js
26
lib/index.js
@ -1,14 +1,15 @@
|
||||
var express = require('express');
|
||||
var cookies = require('cookies');
|
||||
var utils = require('./utils');
|
||||
var Storage = require('./storage');
|
||||
var Config = require('./config');
|
||||
var UError = require('./error').UserError;
|
||||
var Middleware = require('./middleware');
|
||||
var basic_auth = Middleware.basic_auth;
|
||||
var validate_name = Middleware.validate_name;
|
||||
var media = Middleware.media;
|
||||
var expect_json = Middleware.expect_json;
|
||||
var express = require('express')
|
||||
, cookies = require('cookies')
|
||||
, utils = require('./utils')
|
||||
, Storage = require('./storage')
|
||||
, Config = require('./config')
|
||||
, UError = require('./error').UserError
|
||||
, Middleware = require('./middleware')
|
||||
, Logger = require('./logger')
|
||||
, basic_auth = Middleware.basic_auth
|
||||
, validate_name = Middleware.validate_name
|
||||
, media = Middleware.media
|
||||
, expect_json = Middleware.expect_json
|
||||
|
||||
module.exports = function(config_hash) {
|
||||
var config = new Config(config_hash);
|
||||
@ -46,8 +47,7 @@ module.exports = function(config_hash) {
|
||||
res.send({error: err.msg || err.message || 'unknown error'});
|
||||
}
|
||||
} else {
|
||||
console.log(err);
|
||||
console.log(err.stack);
|
||||
Logger.logger.error({err: err}, 'unexpected error: @{!err.message}\n@{err.stack}')
|
||||
if (calls == 1) {
|
||||
res.status(500);
|
||||
res.send({error: 'internal server error'});
|
||||
|
@ -140,6 +140,10 @@ Storage.prototype.read_json = function(name, cb) {
|
||||
})
|
||||
}
|
||||
|
||||
Storage.prototype.path_to = function(file) {
|
||||
return this.path + '/' + file
|
||||
}
|
||||
|
||||
Storage.prototype.create = function(name, value, cb) {
|
||||
create(this.path + '/' + name, value, cb);
|
||||
}
|
||||
|
@ -35,6 +35,16 @@ function get_boilerplate(name) {
|
||||
};
|
||||
}
|
||||
|
||||
Storage.prototype._internal_error = function(err, file, msg) {
|
||||
this.logger.error( {err: err, file: this.storage.path_to(file)}
|
||||
, msg + ' @{file}: @{!err.message}'
|
||||
)
|
||||
return new UError({
|
||||
status: 500,
|
||||
msg: 'internal server error'
|
||||
})
|
||||
}
|
||||
|
||||
Storage.prototype.add_package = function(name, metadata, callback) {
|
||||
this.storage.create_json(name + '/' + info_file, get_boilerplate(name), function(err) {
|
||||
if (err && err.code === 'EEXISTS') {
|
||||
@ -60,15 +70,16 @@ Storage.prototype.remove_package = function(name, callback) {
|
||||
}
|
||||
|
||||
Storage.prototype._read_create_package = function(name, callback) {
|
||||
var self = this;
|
||||
self.storage.read_json(name + '/' + info_file, function(err, data) {
|
||||
var self = this
|
||||
, file = name + '/' + info_file
|
||||
self.storage.read_json(file, function(err, data) {
|
||||
// TODO: race condition
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
// if package doesn't exist, we create it here
|
||||
data = get_boilerplate(name);
|
||||
} else {
|
||||
return callback(err);
|
||||
return callback(self._internal_error(err, file, 'error reading'))
|
||||
}
|
||||
}
|
||||
callback(null, data);
|
||||
@ -251,7 +262,7 @@ Storage.prototype.get_package = function(name, callback) {
|
||||
msg: 'no such package available'
|
||||
}))
|
||||
} else {
|
||||
self.logger.error({err: err, file: file}, 'error reading file @{file}: @{!err.message}')
|
||||
return callback(self._internal_error(err, file, 'error reading'))
|
||||
}
|
||||
}
|
||||
callback.apply(null, arguments)
|
||||
|
Loading…
Reference in New Issue
Block a user