Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Ensure Client resolves/rejects responses from server.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartc committed Jul 27, 2016
1 parent fafe5ee commit efe0f65
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
26 changes: 16 additions & 10 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand All @@ -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);
}
});
}
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
26 changes: 16 additions & 10 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})
})
Expand All @@ -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);
}
})
}
Expand Down

0 comments on commit efe0f65

Please sign in to comment.