mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(rest) add try-catch
This commit is contained in:
parent
7fd5cf1f10
commit
939114466f
2 changed files with 27 additions and 5 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue