Unverified Commit cc10dee3 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #24 from ethereum/feedback

Feedback in case of error
parents 3ce31978 b533d239
...@@ -19,6 +19,7 @@ class Router { ...@@ -19,6 +19,7 @@ class Router {
} }
call (callid, name, fn, args) { call (callid, name, fn, args) {
try {
servicesList[name][fn](args, (error, data) => { servicesList[name][fn](args, (error, data) => {
var response = { var response = {
id: callid, id: callid,
...@@ -29,6 +30,18 @@ class Router { ...@@ -29,6 +30,18 @@ class Router {
} }
this.websocket.send(JSON.stringify(response)) this.websocket.send(JSON.stringify(response))
}) })
} catch (e) {
var msg = 'Unexpected Error ' + e.message
console.log('\x1b[31m%s\x1b[0m', '[ERR] ' + msg)
if (this.websocket) {
this.websocket.send(JSON.stringify({
id: callid,
type: 'reply',
scope: name,
error: msg
}))
}
}
} }
} }
......
...@@ -12,7 +12,11 @@ module.exports = { ...@@ -12,7 +12,11 @@ module.exports = {
}, },
list: function (args, cb) { list: function (args, cb) {
try {
cb(null, utils.walkSync(this.sharedFolder, {}, this.sharedFolder)) cb(null, utils.walkSync(this.sharedFolder, {}, this.sharedFolder))
} catch (e) {
cb(e.message)
}
}, },
resolveDirectory: function (args, cb) { resolveDirectory: function (args, cb) {
...@@ -20,12 +24,15 @@ module.exports = { ...@@ -20,12 +24,15 @@ module.exports = {
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
cb(null, utils.resolveDirectory(path, this.sharedFolder)) cb(null, utils.resolveDirectory(path, this.sharedFolder))
} catch (e) { } catch (e) {
cb(e) cb(e.message)
} }
}, },
get: function (args, cb) { get: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (!fs.existsSync(path)) {
return cb('File not found ' + path)
}
if (!isRealPath(path, cb)) return if (!isRealPath(path, cb)) return
isbinaryfile(path, (error, isBinary) => { isbinaryfile(path, (error, isBinary) => {
if (error) console.log(error) if (error) console.log(error)
...@@ -57,6 +64,9 @@ module.exports = { ...@@ -57,6 +64,9 @@ module.exports = {
rename: function (args, cb) { rename: function (args, cb) {
var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder) var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder)
if (!fs.existsSync(oldpath)) {
return cb('File not found ' + oldpath)
}
var newpath = utils.absolutePath(args.newPath, this.sharedFolder) var newpath = utils.absolutePath(args.newPath, this.sharedFolder)
if (!isRealPath(oldpath, cb)) return if (!isRealPath(oldpath, cb)) return
fs.move(oldpath, newpath, (error, data) => { fs.move(oldpath, newpath, (error, data) => {
...@@ -67,6 +77,9 @@ module.exports = { ...@@ -67,6 +77,9 @@ module.exports = {
remove: function (args, cb) { remove: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (!fs.existsSync(path)) {
return cb('File not found ' + path)
}
if (!isRealPath(path, cb)) return if (!isRealPath(path, cb)) return
fs.remove(path, (error, data) => { fs.remove(path, (error, data) => {
if (error) console.log(error) if (error) console.log(error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment