feature(rest) add try-catch

This commit is contained in:
coderaiser 2015-03-10 08:47:37 -04:00
parent 7fd5cf1f10
commit 939114466f
2 changed files with 27 additions and 5 deletions

View file

@ -29,10 +29,31 @@
ponse = require('ponse'),
rendy = require('rendy'),
copymitter = require('copymitter'),
tryCatch = require('try-catch'),
Modules = require(DIR_JSON + 'modules'),
isWin32 = process.platform === 'win32';
isWin32 = process.platform === 'win32',
json = {
parse: function(str) {
return this._try(str, JSON.parse);
},
stringify: function(json) {
return this._try(json, JSON.stringify);
},
_try: function(data, fn) {
var ret;
tryCatch(function() {
ret = fn.call(JSON, data);
});
return ret;
}
};
/**
* rest interface
@ -129,7 +150,7 @@
switch(cmd) {
case '':
p.data = Util.json.stringify({
p.data = json.stringify({
info: 'Cloud Commander API v1'
});
@ -172,12 +193,12 @@
if (name[0] === '/')
cmd = name.replace('/', '');
files = Util.json.parse(body);
files = json.parse(body);
switch(cmd) {
case 'auth':
auth(body, function(error, token) {
callback(error, Util.json.stringify({
callback(error, json.stringify({
data: token
}));
});
@ -364,7 +385,7 @@
isObj = Util.type.object(dataParam);
if (isObj)
data = Util.json.stringify(dataParam);
data = json.stringify(dataParam);
else
data = dataParam;

View file

@ -51,6 +51,7 @@
"rendy": "~1.0.2",
"restafary": "~1.1.0",
"socket.io": "~1.3.3",
"try-catch": "~1.0.0",
"tryrequire": "~1.1.5"
},
"devDependencies": {