Skip to content
Discussion options

You must be logged in to vote

You can throw from afterResponse and use ky.retry() to catch it:

import ky from 'ky';

const api = ky.extend({
	retry: {
		limit: 3,
	},
	hooks: {
		afterResponse: [
			async (_request, _options, response) => {
				if (response.status === 200) {
					const data = await response.clone().json();
					if (data.error?.code === 'A_RETRIABLE_ERROR_CODE') {
						return ky.retry();
					}
				}
			}
		]
	}
});

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@sindresorhus
Comment options

Comment options

You must be logged in to vote
3 replies
@sindresorhus
Comment options

@MrSquaare
Comment options

@sindresorhus
Comment options

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
3 participants