Skip to content

Commit

Permalink
Throw timeouts even if throwHttpErrors is false (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
sholladay committed May 4, 2021
1 parent ca098f8 commit eefcde5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 1 addition & 3 deletions source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ export class Ky {
return this._retry(fn);
}

if (this._options.throwHttpErrors) {
throw error;
}
throw error;
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,26 @@ test('throwHttpErrors option with POST', async t => {
await server.close();
});

test('throwHttpErrors:false does not suppress timeout errors', async t => {
let requestCount = 0;

const server = await createHttpTestServer();
server.get('/', async (_request, response) => {
requestCount++;
await delay(1000);
response.sendStatus(500);
});

await t.throwsAsync(
ky(server.url, {throwHttpErrors: false, timeout: 500}).text(),
{instanceOf: ky.TimeoutError}
);

t.is(requestCount, 1);

await server.close();
});

test('ky.create()', async t => {
const server = await createHttpTestServer();
server.get('/', (request, response) => {
Expand Down

0 comments on commit eefcde5

Please sign in to comment.