Open thojanssens opened 8 months ago
import ky from 'ky';
const response = await ky('https://example.com', {
hooks: {
beforeRetry: [
async ({error}) => {
if (!isNetworkError(error)) {
throw error;
}
}
]
},
retry: {
limit: 2, // Number of retry attempts
methods: ['get'], // Methods to retry
statusCodes: [0] // Include network errors (status code 0)
}
});
However, I think it would be useful if Ky had a retry.shouldRetry
function. Then it could simply be:
import ky from 'ky';
const response = await ky('https://example.com', {
retry: {
shouldRetry: ({error}) => isNetworkError(error)
}
});
We have these errors happening only occasionally and I'm not able to reproduce these errors.
Is it possible to retry only when errors are network errors: https://github.com/sindresorhus/is-network-error/blob/main/index.js ?
Does anyone know what causes these errors? Is it normal to explicitly catch and handle these specific errors or is it more likely a problem on my app or server? The server is just a Hetzner VPS with very basic configuration, I can't imagine it being that with the popularity that Hetzner has; as to the app, it only happens very occasionally, the same request will succeed after any subsequent attempt.