-
-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If agent fails, try again without #1654
Comments
It should be possible to remove the |
Let's keep this issue open. This needs a test. |
I can't use that hook, as I am streaming ... |
In that case - yes, it's possible: https://github.com/sindresorhus/got#retry |
Yeah I looked at that - but I couldn't get that to work. Just to confirm with that sample code, the writeStream is the stream that represents the actual response that I can stream further along in my pipeline? |
This is still possible with Got v11.8.2: const https = require('https');
const got = require('got');
class MyAgent extends https.Agent {
createConnection(port, options, callback) {
console.log(`Connecting with MyAgent`);
return https.Agent.prototype.createConnection.call(this, port, options, callback);
}
}
const fn = retryCount => {
const stream = got.stream('https://httpbin.org/status/408', {
agent: {
https: retryCount === 0 ? new MyAgent() : undefined
}
});
stream.retryCount = retryCount;
stream.on('retry', (retryCount, error) => {
console.log('Creating new retry:', retryCount);
fn(retryCount);
}).on('error', error => {
console.log('Retry count:', error.request.retryCount);
}).resume().on('end', () => {
console.log('`end` event');
});
};
fn(0); |
If I start up a stream request with an agent (proxy), and that request fails (if say the proxy is unavailable), is there an easy way to fallback to making the call without the agent?
The text was updated successfully, but these errors were encountered: