Skip to content
Snippets Groups Projects
Commit 43abae4d authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #743 Uncaught error when using `config [something]` command

parent 5be618e2
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ const pjson = require('../package.json');
const duniter = require('../index');
const Peer = require('../app/lib/entity/peer');
const Block = require('../app/lib/entity/block');
const constants = require('../app/lib/constants');
let currentCommand = Promise.resolve(true);
......@@ -60,9 +61,12 @@ function subCommand(promiseFunc) {
let result = yield promiseFunc.apply(null, args);
onResolve(result);
} catch (e) {
logger.error(e);
if (e && e.uerr) {
onReject(e.uerr.message);
} else {
onReject(e);
}
}
})
};
}
......@@ -456,7 +460,7 @@ program
let init = ['data', 'all'].indexOf(type) !== -1 ? server : connect;
return init(function (server) {
if (!~['config', 'data', 'peers', 'stats', 'all'].indexOf(type)) {
throw Error('Bad command: usage `reset config`, `reset data`, `reset peers`, `reset stats` or `reset all`');
throw constants.ERRORS.CLI_CALLERR_RESET;
}
return co(function*() {
try {
......@@ -774,6 +778,9 @@ function needsToBeLaunchedByScript() {
function configure(server, conf) {
return co(function *() {
if (typeof server == "string" || typeof conf == "string") {
throw constants.ERRORS.CLI_CALLERR_CONFIG;
}
let wiz = wizard();
conf.upnp = !program.noupnp;
const autoconfNet = program.autoconf
......
......@@ -65,6 +65,8 @@ module.exports = {
SANDBOX_FOR_TRANSACTION_IS_FULL: { httpCode: 503, uerr: { ucode: 1010, message: "The transactions' sandbox is full. Please retry with another document or retry later." }},
NO_POTENTIAL_FORK_AS_NEXT: { httpCode: 503, uerr: { ucode: 1011, message: "No fork block exists in the database as a potential next block." }},
INCONSISTENT_DB_MULTI_TXS_SAME_HASH: { httpCode: 503, uerr: { ucode: 1012, message: "Several transactions written with the same hash." }},
CLI_CALLERR_RESET: { httpCode: 503, uerr: { ucode: 1013, message: "Bad command: usage is `reset config`, `reset data`, `reset peers`, `reset stats` or `reset all`" }},
CLI_CALLERR_CONFIG: { httpCode: 503, uerr: { ucode: 1014, message: "Bad command: usage is `config`." }},
HTTP_PARAM_PUBKEY_REQUIRED: { httpCode: 400, uerr: { ucode: 1101, message: "Parameter `pubkey` is required" }},
HTTP_PARAM_IDENTITY_REQUIRED: { httpCode: 400, uerr: { ucode: 1102, message: "Parameter `identity` is required" }},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment