[got] Add errorCodes to RetryOptions

This commit is contained in:
ikokostya
2019-01-08 23:18:15 +03:00
parent a66df381a0
commit 3635e0a8ec
2 changed files with 25 additions and 2 deletions
+20 -1
View File
@@ -265,8 +265,27 @@ got('https://todomvc.com', { rejectUnauthorized: false });
got('/examples/angularjs', { baseUrl: 'http://todomvc.com' });
got('http://todomvc.com', { headers: { foo: 'bar'} });
got('http://todomvc.com', { cookieJar: new tough.CookieJar() });
// Test retry options.
got('http://todomvc.com', { retry: 2 });
got('http://todomvc.com', { retry: { retries: 2, methods: ['GET'], statusCodes: [408, 504], maxRetryAfter: 1 } });
got('http://todomvc.com', {
retry: {
retries: 2,
methods: ['GET'],
statusCodes: [408, 504],
maxRetryAfter: 1,
errorCodes: ['ETIMEDOUT']
}
});
// Test custom retry error code. See https://github.com/sindresorhus/got/blob/9f3a09948ff80057b12af0af60846cc5b8f0372d/test/retry.js#L155
got('http://todomvc.com', {
retry: {
retries: 1,
methods: ['GET'],
errorCodes: ['OH_SNAP']
}
});
got('http://todomvc.com', { throwHttpErrors: false });
got('http://todomvc.com', { hooks: { beforeRequest: [ () => 'foo']} });
+5 -1
View File
@@ -1,4 +1,4 @@
// Type definitions for got 9.3
// Type definitions for got 9.4
// Project: https://github.com/sindresorhus/got#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Linus Unnebäck <https://github.com/LinusU>
@@ -226,6 +226,10 @@ declare namespace got {
methods?: Array<'GET' | 'PUT' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE'>;
statusCodes?: Array<408 | 413 | 429 | 500 | 502 | 503 | 504>;
maxRetryAfter?: number;
/**
* Allowed error codes.
*/
errorCodes?: string[];
}
interface AgentOptions {