diff --git a/lib/Client.js b/lib/Client.js index 8b4f4cf..6c3eb29 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -24,9 +24,10 @@ function clientPost(_ref) { json: body }, function (error, response, body) { if (error) { - console.log(error); + reject(error); } else { - console.log("Posted successfully."); + console.log("POST succeeded."); + resolve(body); } }); }); @@ -51,19 +52,24 @@ function getThenPost(_ref2) { 'pass': password, 'sendImmediately': sendImmediately } - }, function (error, response, body) { - if (error) { - console.log(error); + }, function (error, response, getResponseBody) { + if ([200, 201, 202].indexOf(response.statusCode) == -1 || error) { + console.log("GET failed."); + // TODO: construct a useful error message, request returns a blank + // error when the server responds, and the response object is massive + // and unserializable. + reject(error); } else { + console.log("GET succeeded."); _request2.default.post({ url: postUrl, - json: JSON.parse(body) - }, function (error, response, body) { + json: JSON.parse(getResponseBody) + }, function (error, response, postResponseBody) { if (error) { - console.log(error); + reject(error); } else { - console.log("Fido fetched successfully."); - console.log("*wags tail*"); + console.log("POST succeeded."); + resolve(getResponseBody); } }); } diff --git a/package.json b/package.json index 16d610c..d936e9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "language-http", - "version": "0.0.3", + "version": "0.0.4", "description": "An HTTP Language Pack for OpenFn", "main": "lib/index.js", "scripts": { @@ -14,11 +14,8 @@ "lib/" ], "dependencies": { - "JSONPath": "^0.10.0", "language-common": "github:openfn/language-common", - "lodash-fp": "^0.10.2", - "request": "^2.72.0", - "superagent": "^1.7.2" + "request": "^2.72.0" }, "devDependencies": { "assertion-error": "^1.0.1", diff --git a/src/Client.js b/src/Client.js index 0db286b..c68814c 100644 --- a/src/Client.js +++ b/src/Client.js @@ -7,9 +7,10 @@ export function clientPost({ username, password, body, url }) { json: body }, function(error, response, body){ if(error) { - console.log(error); + reject(error); } else { - console.log("Posted successfully.") + console.log("POST succeeded."); + resolve(body); } }) }) @@ -27,19 +28,24 @@ export function getThenPost({ username, password, query, url, sendImmediately, p 'pass': password, 'sendImmediately': sendImmediately } - }, function(error, response, body){ - if(error) { - console.log(error); + }, function(error, response, getResponseBody){ + if ([200,201,202].indexOf(response.statusCode) == -1 || error) { + console.log("GET failed."); + // TODO: construct a useful error message, request returns a blank + // error when the server responds, and the response object is massive + // and unserializable. + reject(error); } else { + console.log("GET succeeded."); request.post ({ url: postUrl, - json: JSON.parse(body) - }, function(error, response, body){ + json: JSON.parse(getResponseBody) + }, function(error, response, postResponseBody){ if(error) { - console.log(error); + reject(error); } else { - console.log("Fido fetched successfully.") - console.log("*wags tail*") + console.log("POST succeeded."); + resolve(getResponseBody); } }) }