-
Notifications
You must be signed in to change notification settings - Fork 127
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
Timeout feature #21
Comments
Would very much like to see timeouts implemented - preferably with an exponential increase in timeout duration on subsequent retries. This is a much needed and essential feature coming from relying on it with axios. Can we hook into the Something like: $fetch(event.req.url, {
baseURL: config.public.baseUrl,
params,
method,
body,
retry: 10,
timeout: 2000, // signal: AbortSignal.timeout(2000),
... |
|
+1, would be a very useful feature to have. Currently have to hack around to get this to work in nuxt |
It could be implemented using https://npm.im/async-retry or adapted directly from the source code of https://github.com/tim-kos/node-retry to avoid adding a dependency. EDIT: or perhaps just: - function onError(context: FetchContext): Promise<FetchResponse<any>> {
+ async function onError(context: FetchContext): Promise<FetchResponse<any>> {
// Is Abort
// If it is an active abort, it will not retry automatically.
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException#error_names
const isAbort =
(context.error && context.error.name === "AbortError") || false;
// Retry
if (context.options.retry !== false && !isAbort) {
let retries;
if (typeof context.options.retry === "number") {
retries = context.options.retry;
} else {
retries = isPayloadMethod(context.options.method) ? 0 : 1;
}
const responseCode = (context.response && context.response.status) || 500;
if (retries > 0 && retryStatusCodes.has(responseCode)) {
+ context.options.timeout ??= 1000;
+ await new Promise(resolve => setTimeout(resolve, context.options.timeout));
+ context.options.timeout *= 2;
return $fetchRaw(context.request, {
...context.options,
retry: retries - 1,
});
}
} |
@rmcmk Can you share the workaround you are using in Nuxt. |
Very much needed! |
Looking forward to having this implemented ! |
implemented in #268 (finally!) |
Timeout support (limiting the request execution time) would allow for snappy client-facing network timeout error messages if network connectivity drops.
The text was updated successfully, but these errors were encountered: