mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 17:05:17 +00:00
feature(pipe) getBody: add error handling
This commit is contained in:
parent
1e825698c3
commit
e4d376c61c
5 changed files with 65 additions and 33 deletions
|
|
@ -40,11 +40,11 @@
|
|||
code = code.replace('code=', '');
|
||||
|
||||
Util.log(code);
|
||||
authenticate(code, function(token) {
|
||||
authenticate(code, function(error, token) {
|
||||
var result = { "token": token };
|
||||
Util.log(result);
|
||||
Util.log(error || result);
|
||||
|
||||
Util.exec(callback, result);
|
||||
Util.exec(callback, error, result);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -71,8 +71,17 @@
|
|||
GithubAuth.headers = { 'content-length': data.length };
|
||||
|
||||
req = https.request(GithubAuth, function(res) {
|
||||
pipe.getBody(res, function(body) {
|
||||
Util.exec(callback, qs.parse(body).access_token);
|
||||
pipe.getBody(res, function(error, body) {
|
||||
var parsed, token;
|
||||
|
||||
if (!error) {
|
||||
parsed = qs.parse(body);
|
||||
|
||||
if (parsed)
|
||||
token = parsed.access_token;
|
||||
}
|
||||
|
||||
Util.exec(callback, error, token);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
'# http://cloudcmd.io' + '\n');
|
||||
|
||||
var main = global.cloudcmd.main,
|
||||
Util = require('util.io'),
|
||||
Util = main.util,
|
||||
fs = require('fs'),
|
||||
zlib = require('zlib');
|
||||
|
||||
|
|
|
|||
|
|
@ -93,17 +93,17 @@
|
|||
*
|
||||
* @param pParams {command, method, body, requrest, response}
|
||||
*/
|
||||
function sendData(pParams) {
|
||||
function sendData(params) {
|
||||
var p, isFS, isMD,
|
||||
ret = main.checkParams(pParams);
|
||||
ret = main.checkParams(params);
|
||||
|
||||
if (ret) {
|
||||
p = pParams;
|
||||
p = params;
|
||||
isFS = Util.isContainStrAtBegin(p.name, CloudFunc.FS),
|
||||
isMD = Util.isContainStrAtBegin(p.name, '/markdown');
|
||||
|
||||
if (isFS)
|
||||
onFS(pParams);
|
||||
onFS(params);
|
||||
else if (isMD)
|
||||
markdown.operate(p.name, p.request, function(error, data) {
|
||||
if (error)
|
||||
|
|
@ -117,13 +117,17 @@
|
|||
|
||||
switch(p.request.method) {
|
||||
case 'GET':
|
||||
ret = onGET(pParams);
|
||||
ret = onGET(params);
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
pipe.getBody(p.request, function(pBody) {
|
||||
p.body = pBody;
|
||||
onPUT(p);
|
||||
pipe.getBody(p.request, function(error, body) {
|
||||
if (error)
|
||||
sendError(params, error);
|
||||
else {
|
||||
p.body = body;
|
||||
onPUT(params);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
@ -169,19 +173,29 @@
|
|||
break;
|
||||
|
||||
case 'DELETE':
|
||||
pipe.getBody(p.request, function(body) {
|
||||
var files = Util.parseJSON(body);
|
||||
pipe.getBody(p.request, function(error, body) {
|
||||
var files;
|
||||
|
||||
onDelete(p.name, files, query, function(error, callback) {
|
||||
checkSendError(error, params, function() {
|
||||
var names = (files && files.length) ? files : p.name;
|
||||
if (error)
|
||||
sendError(p, error);
|
||||
else {
|
||||
files = Util.parseJSON(body);
|
||||
|
||||
onDelete(p.name, files, query, function(error, callback) {
|
||||
var names;
|
||||
|
||||
if (callback)
|
||||
Util.exec(callback);
|
||||
else
|
||||
sendMsg(params, 'delete', names);
|
||||
if (error)
|
||||
sendError(params,error);
|
||||
else {
|
||||
names = (files && files.length) ? files : p.name;
|
||||
|
||||
if (callback)
|
||||
Util.exec(callback);
|
||||
else
|
||||
sendMsg(params, 'delete', names);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
@ -238,11 +252,14 @@
|
|||
|
||||
switch(lCmd) {
|
||||
case 'auth':
|
||||
main.auth(p.body, function(pTocken) {
|
||||
send({
|
||||
response: p.response,
|
||||
data: pTocken
|
||||
});
|
||||
main.auth(p.body, function(error, token) {
|
||||
if (error)
|
||||
sendError(p, error);
|
||||
else
|
||||
send({
|
||||
response: p.response,
|
||||
data: token
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,11 @@
|
|||
|
||||
if (!error)
|
||||
if (size < MAX_SIZE)
|
||||
pipe.getBody(readStream, function(patch) {
|
||||
patchFile(patch);
|
||||
pipe.getBody(readStream, function(error, patch) {
|
||||
if (error)
|
||||
func(error);
|
||||
else
|
||||
patchFile(patch);
|
||||
});
|
||||
else
|
||||
error = 'File is to big. ' +
|
||||
|
|
|
|||
|
|
@ -32,8 +32,11 @@
|
|||
|
||||
case 'PUT':
|
||||
|
||||
pipe.getBody(request, function(data) {
|
||||
parse(data, callback);
|
||||
pipe.getBody(request, function(error, data) {
|
||||
if (error)
|
||||
Util.exec(callback, error);
|
||||
else
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue