Skip to content
Discussion options

You must be logged in to vote

We have a test to prove that ky.stop works.

ky/test/hooks.ts

Lines 502 to 532 in 3cf5064

test('beforeRetry hook can cancel retries by returning `stop`', async t => {
let requestCount = 0;
const server = await createHttpTestServer();
server.get('/', async (request, response) => {
requestCount++;
if (requestCount > 2) {
response.end(request.headers['unicorn']);
} else {
response.sendStatus(408);
}
});
await ky.get(server.url, {
hooks: {
beforeRetry: [
({error, retryCount}) => {
t.truthy(error);
t.is(retryCount, 1);
return ky.stop;
},
],
},
});
t.is(

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #550 on December 19, 2023 21:36.