diff --git a/source/as-promise/index.ts b/source/as-promise/index.ts index 4d8d5e041..8f3698ede 100644 --- a/source/as-promise/index.ts +++ b/source/as-promise/index.ts @@ -125,7 +125,7 @@ export default function asPromise(normalizedOptions: NormalizedOptions): Canc } globalResponse = response; - + if (!isResponseOk(response)) { request._beforeError(new HTTPError(response)); return; diff --git a/source/core/calculate-retry-delay.ts b/source/core/calculate-retry-delay.ts index 56ea3c0db..3b584bfcc 100644 --- a/source/core/calculate-retry-delay.ts +++ b/source/core/calculate-retry-delay.ts @@ -10,7 +10,7 @@ const calculateRetryDelay: Returns = ({attemptCount, retr } const hasMethod = retryOptions.methods.includes(error.options.method); - const hasErrorCode = retryOptions.errorCodes.includes(error.code!); + const hasErrorCode = retryOptions.errorCodes.includes(error.code); const hasStatusCode = error.response && retryOptions.statusCodes.includes(error.response.statusCode); if (!hasMethod || (!hasErrorCode && !hasStatusCode)) { return 0; diff --git a/source/types.ts b/source/types.ts index 60d82e2c8..f2ea8516b 100644 --- a/source/types.ts +++ b/source/types.ts @@ -104,6 +104,16 @@ export type OptionsWithPagination = Merge(url: string | URL, options?: OptionsWithPagination): AsyncIterableIterator; + + /** + Same as `GotPaginate.each`. + */ + (options?: OptionsWithPagination): AsyncIterableIterator; + /** Returns an async iterator. @@ -150,16 +160,6 @@ export interface GotPaginate { */ all: ((url: string | URL, options?: OptionsWithPagination) => Promise) & ((options?: OptionsWithPagination) => Promise); - - /** - Same as `GotPaginate.each`. - */ - (url: string | URL, options?: OptionsWithPagination): AsyncIterableIterator; - - /** - Same as `GotPaginate.each`. - */ - (options?: OptionsWithPagination): AsyncIterableIterator; } export interface GotRequestFunction { diff --git a/test/arguments.ts b/test/arguments.ts index 5088b898a..37b3e1264 100644 --- a/test/arguments.ts +++ b/test/arguments.ts @@ -223,16 +223,6 @@ test('can omit `url` option if using `prefixUrl`', withServer, async (t, server, await t.notThrowsAsync(got({})); }); -test('throws TypeError when `options.hooks` is not an object', async t => { - await t.throwsAsync( - // @ts-expect-error Error tests - got('https://example.com', {hooks: 'not object'}), - { - message: 'Expected value which is `predicate returns truthy for any value`, received value of type `Array`.' - } - ); -}); - test('throws TypeError when known `options.hooks` value is not an array', async t => { await t.throwsAsync( // @ts-expect-error Error tests diff --git a/test/error.ts b/test/error.ts index cf9203d33..122c9d773 100644 --- a/test/error.ts +++ b/test/error.ts @@ -182,15 +182,6 @@ test('`http.request` error through CacheableRequest', async t => { }); }); -test('errors are thrown directly when options.isStream is true', t => { - t.throws(() => { - // @ts-expect-error Error tests - void got('https://example.com', {isStream: true, hooks: false}); - }, { - message: 'Expected value which is `predicate returns truthy for any value`, received value of type `Array`.' - }); -}); - test('normalization errors using convenience methods', async t => { const url = 'undefined/https://example.com'; await t.throwsAsync(got(url).json().text().buffer(), {message: `Invalid URL: ${url}`}); diff --git a/test/http.ts b/test/http.ts index da820717f..4c98defa8 100644 --- a/test/http.ts +++ b/test/http.ts @@ -16,7 +16,8 @@ const testIPv6 = (IPv6supported && process.env.TRAVIS_DIST !== 'bionic' && proce const echoIp: Handler = (request, response) => { const address = request.connection.remoteAddress; if (address === undefined) { - return response.end(); + response.end(); + return; } // IPv4 address mapped to IPv6 diff --git a/test/retry.ts b/test/retry.ts index 4647cc7a4..ba7ac2318 100644 --- a/test/retry.ts +++ b/test/retry.ts @@ -171,7 +171,11 @@ test('custom error codes', async t => { request: () => { const emitter = new EventEmitter() as http.ClientRequest; emitter.abort = () => {}; + + // @ts-expect-error emitter.end = () => {}; + + // @ts-expect-error emitter.destroy = () => {}; const error = new Error('Snap!'); @@ -184,7 +188,7 @@ test('custom error codes', async t => { }, retry: { calculateDelay: ({error}) => { - t.is(error.code as string as typeof errorCode, errorCode); + t.is(error.code, errorCode); return 0; }, methods: [