|
|
@ -96,7 +96,7 @@ client.prototype.request = function(method, path, params, callback){ |
|
|
path: path, |
|
|
path: path, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if(http_options['method'] == 'POST'){ |
|
|
|
|
|
|
|
|
if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){ |
|
|
http_options['headers'] = { |
|
|
http_options['headers'] = { |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Length': body.length, |
|
|
'Content-Length': body.length, |
|
|
@ -116,17 +116,20 @@ client.prototype.request = function(method, path, params, callback){ |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
res.on('end', function(){ |
|
|
res.on('end', function(){ |
|
|
if(res.headers['content-type'] == 'application/json'){ |
|
|
|
|
|
data = JSON.parse(data); |
|
|
|
|
|
|
|
|
error = null; |
|
|
|
|
|
try{ data = JSON.parse(data); }catch(e){} |
|
|
|
|
|
if(data['errors']){ |
|
|
|
|
|
error = data['errors']; |
|
|
|
|
|
data = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(v8type.is(callback, v8type.FUNCTION)){ |
|
|
if(v8type.is(callback, v8type.FUNCTION)){ |
|
|
callback(null, data, res.statusCode); |
|
|
|
|
|
|
|
|
callback(error, data, res.statusCode); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if(http_options['method'] == 'POST'){ |
|
|
|
|
|
|
|
|
if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){ |
|
|
req.write(body); |
|
|
req.write(body); |
|
|
} |
|
|
} |
|
|
req.end() |
|
|
req.end() |
|
|
|