Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

node request could not wait until response, even using callback #25981

Closed
isian8814 opened this issue Apr 5, 2016 · 1 comment
Closed

node request could not wait until response, even using callback #25981

isian8814 opened this issue Apr 5, 2016 · 1 comment

Comments

@isian8814
Copy link

Here is the code I am testing, it does not return response every time. Like I run it 20 times, there is only one time I could get output of the body. Other times, I got nothing output, even not seeing any error messages.

I guess it is because the request runs too fast to get response back.

Could anyone help me with this?
Thanks.

I added output within the function(err,response,body), like below. But nothing got output.
get_from_google : function (callback) {
request('http://www.google.com', function(err, res, body) {
console.info('In the callback');
if (err)
return callback(err);
if (res.statusCode === 200) {
callback(new Error('Nothing got back'), body);
} else {
callback(new Error('Unexpected status code: ' + res.statusCode));
}
});
}

Here is console output:
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://10.33.203.210:53537/wd/hub
Started
.

Ran 1 of 3 specs
1 spec, 0 failures
Finished in 0.019 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed

Process finished with exit code 0

@evanlucas
Copy link

Hi @isian8814. Thanks for opening the issue. This doesn't appear to be an issue with Node.js core, so could you please open the issue at https://github.com/nodejs/help? Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants