-
-
Notifications
You must be signed in to change notification settings - Fork 362
-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to handle Fetch errors such as Failed to fetch, NetworkError when attempting to fetch resource, etc. #545
Comments
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 import ky from 'ky';
const response = await ky('https://example.com', {
retry: {
shouldRetry: ({error}) => isNetworkError(error)
}
});
|
I think we should wrap fetch errors in a We could potentially also update our retry logic to only retry However, that does mean that if a new runtime comes along with a different error message unknown to An alternative approach would be to detect errors that shouldn't be retried, such as type errors caused by malformed options, and then retry everything else. It just depends on whether you want to err on the side of retries or not, when the error message is unknown. I would prefer retries, myself. |
👍
That sounds like the most pragmatic solution.
Unfortunate yes, but the benefits may outweigh this single downside. New runtimes don't come along every day. |
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.
The text was updated successfully, but these errors were encountered: